3

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.

3 Answers 3

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.

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

1 Comment

Using the old "version number in query string" trick really is the way to fly.
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.

Comments

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

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.