Reputation: 46979
<script type="text/javascript" src="main.js"></script>
If This is in the my header page and which is included in all pages.My question is that when there are any changes in main.js the user has to refresh his browsers cache.So instead of this if we use
<script type="text/javascript" src="main.js?1"></script>
user would get latest changes without refreshing the cache.If again a change ismade in main.js change has to be made like
<script type="text/javascript" src="main.js?sumnumber"></script>
My question is that is there any generic way to do this
Upvotes: 1
Views: 481
Reputation: 4857
if you are looking for every request from the same browser to force re-download, then you want the url to change every time, e.g.
<script type="text/javascript">
document.write('<script type="text/javascript" src="main.js?' +Math.random()+ '"></script>');
</script>
Upvotes: 0
Reputation: 29668
You can use Date.geTime() or some such which returns the ticks, it's a common way to cache bust.
However, generating the tags will be more of a pain.
You can of course turn of caching on the web server side so that your page shouldn't be cached.
Upvotes: 2
Reputation: 274878
You can let your Version Control System put in a version number whenever you check-in your source code.
e.g in CVS you can use the $Revision$
keyword:
<script type="text/javascript" src="myfile.js?$Revision$"></script>
Upvotes: 1