Reputation: 1570
I am having trouble with javascript files being cached by the browser, even though I use
FileETag MTime Size
in htaccess to check the modified time and size to see if it is the latest version. I currently include javascript files like so:
<script src="/code.js" type="text/javascript"></script>
I tried to add SVN revision information to the file call like so:
<script src="/code.js?svn=123" type="text/javascript"></script>
but I could not find a bullet-proof approach to do it, since I could not get a revision by file name (any suggestions) and even though I add the revision, the HTML is being precompiled and cached by Smarty.
So I thought about using no cache blocks for the template, but I haven't tried this approach yet. Will there be any difference since the files are compiled only once?
So basically I'm just collecting ideas on how to force the browser to only cache the latest version of the file. The ideal solution would be through htaccess that actually works, not like FileETag, since with that, you always have to press CTRL+F5 to get the latest version anyway.
Upvotes: 1
Views: 446
Reputation: 57998
adding a cache buster either into the file path is the best way to go. you can do it through the ?
approach like you have here, or add it into a path to the file like: /static/123/code.js
after that you add an expires header 10 years into the future, and you are good to go. So the question you have is how to generate the number in the url. Maybe you can change your deploy script to replace bump that number up when you do the deployment, that way you dont need to care about version numbers
another thought would be to compute an md5 hash of the js file and use that in the path.
Upvotes: 2