How to ensure broswer doesn't cache my JS / CSS

Possible duplicate:
CSS file caching

I want users to always get the latest version of my code.

However, setting it up so that browsers do not cache files is bad, since you would have to download fresh images of each page. I want him not to use the cached copy from the previous version. For example. Using a cached copy of version 1.2 of JS with a site version of 1.3.

One of the ways I've seen involves changing the file name in each version and linking to that different file name in each version (for example, "myscript1.3.js"). This seems like a lot of effort and a little hacked.

Is there a better way to do this?

+1
javascript css browser-cache
source share
2 answers

This is the perfect solution, and I even went so far as to say that this is the best.

You can also use query parameters to indicate the new version (? V = 1 ,? v = 2, ...). But this may reset some public proxies (they may not cache files). See here for more details: https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching

Of course, this will require some effort on your part. But you can automate all this in your deployment process (how to do this will completely depend on your configuration, so I can’t give you a solution without knowing much more about your project).

+3
source share

Method 1. You can change the server headers. They may differ for different servers, but for apache servers you can see the mod_cache module http://httpd.apache.org/docs/2.4/mod/mod_cache.html

Method 2: you use some meta tags. Here you will find the corresponding question. Using <meta> tags to disable caching in all browsers?

-one
source share

All Articles