2

I'm working on an asp.net website. I need to make sure my javascript and css updates will be immediately available for returning visitors, without them having to clear their cache to get the latest code. How can I force this when needed, and leave it alone on other occasions?

Thanks in advance.

nokizon
  • 23
  • 4

3 Answers3

2

Stackoverflow does this very elegantly IMO. You can see in there source there is a query-string variable passed.

<script type="text/javascript" src="http://sstatic.net/js/stub.js?v=778aaf5a38e2"></script>

This will force new load if that changes.

Dustin Laine
  • 37,935
  • 10
  • 86
  • 125
0

In order to reliably force a refresh of cached content on the browser you need to change the name / requested URL of the file somehow.

Often this is done by appending a query string to the URL (which is often ignored)

See When Does Browser Automatically Clear JavaScript Cache? for a more complete discussion.

Community
  • 1
  • 1
Justin
  • 84,773
  • 49
  • 224
  • 367
0

You'll need to apply no-cache header to those resources, alternatively make the url dynamic somehow.

see - http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

RShar
  • 105
  • 3