Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
Is Firefox storing javascript files even if all caches are off ?

I have a site that is simultaneously in use and in development, and every so often I need to update the Javascript. However, visiting browsers (tested in Firefox) will typically use their own cached javascripts even if the server-side copies have changed. This leads to problems, especially when the page markup changes along with the javascript.

The only "solution" I've found is for the client to view-source, click on the offending javascript, and once it has loaded in the view-source window, refresh the view-source window, and then refresh the actual page. This is hardly a solution. Is there any way I can do that transparently, serverside?

share|improve this question

marked as duplicate by Nifle, BinaryMisfit Oct 17 '10 at 8:50

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
More tips on SO –  Nifle Oct 16 '10 at 20:20

1 Answer 1

up vote 4 down vote accepted

The best solution seems to be to append a version string to your requests.

javascript.js?v=xxx

Every time the file changes, update the version string. Of course, the version string doesn't have to do anything, and will always point towards the same file. The browser will reload the javascript file. The advantage here is that you can set the cache lifetime very high to reduce unnecessary load, too.

share|improve this answer
    
that's perfect, thanks! How do I go about setting the cache lifetime high? –  Mala Oct 16 '10 at 17:09
1  
Correct, though sadly enough some badly configured CMS software and the like will in fact erroneously tell the browser not to cache anything when a GET request URL contains parameters. That's easily checked though, by peeking into the response headers. (Like by using Firebug, Web Inspector, or even web-sniffer.net) –  Arjan Oct 16 '10 at 17:18
    
@Mala; That would be the Expires: HTTP header section, or Cache-Control. Both are detailed around the web, web-caching.com/mnot_tutorial/how.html looks good. –  Phoshi Oct 16 '10 at 18:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.