In my ASP.NET page I have
<script src="Common2.js" type="text/javascript" ></script>
How can I force the clients to never cache it so that it is always loaded fresh.
In my ASP.NET page I have
<script src="Common2.js" type="text/javascript" ></script>
How can I force the clients to never cache it so that it is always loaded fresh.
You can add a random query variable to the end of the file path
<script src="Common2.js?randomvar=<SOME RANDOM GUID>" type="text/javascript" ></script>
That will ensure it never caches.
One method, as mentioned by Zoidberg, is to put a random number (or the current time, etc) at the end of the url. However, you probably don't want the clients to never cache it. Caches, used properly, are beautiful things.
Consider using something which only changes when the file does, eg: the file's last-modified time, the file's revision number, or a hash of the contents of the file, etc. This way, the clients will always get a fresh version of it, but only when it's actually fresh!
Take a look at the source of this site:
<script src="http://sstatic.net/so/js/question.js?v=5290">