views:

58

answers:

2

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.

+3  A: 

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.

Zoidberg
Here's the site I'm using it on http://BiblePro.BibleOcean.com I think it's working now. thanks
BahaiResearch.com
+2  A: 

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"&gt;
nickf
Isn't this what Rails does by default, appending the file modification timestamp to the query
Vincent Robert