Reputation: 110502
I have added a pretty substantial change to a javascript file. However, in order for the new changes to register, I need to refresh my browser. I imagine this is how it will be for all the other people using this site as well.
Is there a way to invalidate the client's browser cache and force it to download the new js file?
Upvotes: 1
Views: 1512
Reputation: 2497
For development purposes, I disable the cache on the browser side so that it fetches always.
But for production, to reset so that all client user's browsers should download the new version you can look at apache's settings to expire cached files.
Upvotes: 0
Reputation: 29668
There is a very comprehensive discussion here, with several ways to do this.
The recommended solution (mod_pagespeed) might not be the best solution for you in case your project is not big enough or you don't use apache, in which case I would recommend a format such as:
<script src="/{sha_1_here}/script.js"></script>
instead of a GET parameter, because apparently some browsers do not cache scripts with parameters.
This should work everywhere, and you just need to rewrite the URL server side.
Upvotes: 1
Reputation: 1782
You can rename the file, or just add a random parameter when loading the file:
<script src="/javascripts/application.js?version=4" type="text/javascript"></script>
Upvotes: 4
Reputation: 97717
You can add an argument to the file name, like
<script src="script.js?rnd=2131231"></script>
Upvotes: 3