Is there a way by which we can replace or remove the cached css and js files from client browser when they come to the website next time?
-
You mean after they've been modified or each time? – artm Jun 05 '15 at 11:30
-
possible duplicate of [What is an elegant way to force browsers to reload cached CSS/JS files?](http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files) – GillesC Jun 05 '15 at 11:30
-
@artm Everytime we modify it – Sachin B. R. Jun 05 '15 at 11:32
-
1One simple way is to add a parameter to it, i.e. `...site.css?v=1` and when the css is modified change it to `...site.css?v=2` – artm Jun 05 '15 at 11:33
3 Answers
Yes, give it a version number of sorts. For example, client is on your site and loads:
http://path/to/cssFile.css
If you change this and add a version number, when they visit again they will download it again, e.g.
http://path/to/cssFile.css?version=1.001

- 22,603
- 38
- 120
- 207
Here, I think this can help you out.. at least it works for images:
How to reload/refresh an element(image) in jQuery
Gl =)

- 1
- 1

- 150
- 10
Once you set an expire-date header the client/cache-server will cache it until the specified date for that URL. Describing cache mechanism is very long to wrote here...( if you`re not familiar with it google it )
you don't have any control over it. But! if you change the URL the client will think it is new resource and fetch it from your server again. so try use fake query after your resource to make the trick.
instead of
http:/example.com/static/style_main.css
use:
http:/example.com/static/style_main.css?t=1234
and when you think it is time to change it increment the number.
===
if you well tuned your app and using a good webserver like Apache or nginx to serve this static files, they handle it for you without any effort. because the client will ask the server to give the newest version and it will response with 403 Not Modified or the content of file if it has changed since before.
if your JS/CSS are dynamically changed so the best way is to set its header explicitly not to be cached.

- 1,879
- 2
- 18
- 38