1
<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

1
  • The proper way to do this, is have the server return the correct heads: mnot.net/cache_docs Commented Feb 4, 2011 at 10:08

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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>

3 Comments

How does the browser treat $Revision$??
$Revision$ will be replaced by the file's version number when you check it into source control so the resulting file which you deploy won't have $Revision$.
Is the same behaviour applicable for SVN
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.