Dusty
Dusty

Reputation: 2189

Browser caching javascript and css files

I understand that the browser is forced to fetch a new version of the cached JS file when the file name is changed or a query string is added to it.

We don't do this and until now we've never had issues with browser serving stale files. Recently, we are seeing some users using IE9 who complain about the browser serving cached JS/CSS files. This issue is not consistent across everyone using the site.

My understanding is that when the file name or query string is not changed, but the JS file content is changed, the browser would fetch the new version.

Why is this happening and why is it not consistent?

Any thoughts?

Upvotes: 4

Views: 26254

Answers (3)

Sparky
Sparky

Reputation: 98748

Yes, when the content seems the same (i.e. same file names), users may get a cached version of those files on subsequent visits.

It is really beyond your control... it's up to each specific browser to decide how to handle caching and it's also up to the user... some dump their cache regularly or refresh the page if something doesn't seem right.

If you want to force the user to see your updated CSS or JS content, change the CSS or JS file name... otherwise it may be inconsistent for a short, but unknown, period of time.

This tutorial may help you...

http://www.mnot.net/cache_docs/

Upvotes: 1

mch_dk
mch_dk

Reputation: 369

Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

This is good if we want to actual cache the resource. If we want to force a new download set no-cache, which forces caches to submit the request to the origin server for validation before releasing a cached copy, every time. This is useful to assure that authentication is respected (in combination with public), or to maintain rigid freshness, without sacrificing all of the benefits of caching.

HTTP Server-Specified Expiration - specs

Upvotes: 4

SergeS
SergeS

Reputation: 11779

For example Chrome caches scripts until Shift + F5 or some time expired ( and ignore the fact it is changed on server, it don't even send a request ).

So is done by other browsers ( but when cache is enabled ) - i cannot descripe exactly when it happens

Upvotes: 0

Related Questions