DooDoo
DooDoo

Reputation: 13487

cache javascript file in all pages

I have a question about caching. Consider we have jQuery library in Page1 and has another link to jQuery lib to Page2.

Does page2 use cached version of jQuery in we first request for Page1 then Page2?

Does it depends on Browser? or coding style?

thanks

Upvotes: 0

Views: 411

Answers (3)

TBohnen.jnr
TBohnen.jnr

Reputation: 5129

If the url of the jquery library stays the same then all of the modern browsers will cache that file if it's on default settings, so on the second and all subsequent requests until it's expired it will be retrieved from Cache.

That is 1 of the reasons to use a CDN, so that if the user perhaps visited a site that used the same CDN to the javascript file it will be retrieved from cache.

EDIT

As Daniel Kurka mentioned, the response header can state that the file should not be cached, but this should almost never be the case with a jquery file...

Upvotes: 1

Daniel Kurka
Daniel Kurka

Reputation: 7985

It depends on the http headers of your server when serving the javascript file, as well as the settings of the clients browser.

For a basic explanation you can take a look at: http://www.web-caching.com/mnot_tutorial/how.html

So there is no simple yes or no, if you want the file to be cached you need to validate that you are setting proper headers in your GET responses.

Upvotes: 0

Jahan Zinedine
Jahan Zinedine

Reputation: 14874

Yes that file will be cached, except that you've added it to page2 with another url.

Upvotes: 0

Related Questions