Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure a cached JavaScript and CSS files get reloaded?

Tags:

caching

Could anyone explain how to make sure that if I update my webapp, the user gets the latest version of files?

Should I add a dynamic string ?version=random at the end of script and css files and change it as I roll out updates? Or what is a general strategy here?

Thank you, Boda Cydo.

like image 713
bodacydo Avatar asked Jan 31 '10 21:01

bodacydo


2 Answers

Yes, the way you mention is very common and is a solid approach.

I personally use the Subversion revision number of my files, but you could use anything meaningful to you, even the last updated timestamp of the file.

StackOverflow uses the SVN revision number:

<script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6180">
</script> 
like image 111
Christian C. Salvadó Avatar answered Nov 15 '22 08:11

Christian C. Salvadó


It turns out squid does not cache files with a GET parameter. You would have to use something like script.2010-02-14.js if you want squid to cache the file.

"But which is better: mylogo.1.2.gif or mylogo.gif?v=1.2? To gain the benefit of caching by popular proxies, avoid revving with a querystring and instead rev the filename itself."

http://webcache.googleusercontent.com/search?q=cache:JhDnwSNN-BEJ:www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/+http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/&cd=1&hl=en&ct=clnk&gl=us&client=opera&source=www.google.com

like image 20
Chad Clark Avatar answered Nov 15 '22 09:11

Chad Clark