Reputation: 959
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?
Upvotes: 5
Views: 5514
Reputation: 1959
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.
Upvotes: 0
Reputation: 23989
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
Upvotes: 5