some_bloody_fool
some_bloody_fool

Reputation: 4685

How to avoid browser caching issues by renaming css file

If i have some bad css in site.css file and this has been cached from the user's browser, is it then possible to simply rename the file with the fixed css in order to have the user's browser reload data that had been formerly cached?

If not, is there a way to mimick clearing a browser cache?

Thanks

Upvotes: 1

Views: 1350

Answers (2)

Jannis Froese
Jannis Froese

Reputation: 1407

Yes, you can save the new css file with a new name and edit all files that use the css file to use the new version.

A fake query string like

styles.css?revision=2

or

styles.css?lastchange=2012-09-21

in all files that use the css file also forces all caches to get the updated file.

The advantage is that the file name doesn't have to change.

The drawback is that you won't notice easily whether the old version is still in use somewhere (perhaps because you forgot to update a file). If you instead change the file name, you can leave the old file up for some time and check the logs if it's still accessed to give you this information.

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

If you simply add a dummy querystring value to the css reference the browser will get a fresh copy of the file since different url means different resource. For instance

styles.css?anything=1

Renaming the file would work too but that's not necessary.

Upvotes: 4

Related Questions