2

I version all of my client side JS files like "/js/myfile.js?v=3903948" so that my clients don't need to clear their browser cache to ensure they get the updated files. But every time I push an update, without fail, at least one person runs into a problem where they are running the old version and get some kind of error. I used to think that this was just them having already been on the page during the release and just needing to reload the browser, but this happened to me today when I was definitely not previously on the page. I browsed to the live site and was running the old code. I needed to do a browser refresh on that page to get the new file.

What can cause this?

PS I was using Chrome on Win7, but I have seen clients report this before on all different browsers.

1
  • Are you using an Application Cache? Commented Sep 12, 2011 at 21:24

4 Answers 4

2

If your main web page can also be cached, then the old version of that page can be requesting the old version of the JS file. JS file versioning works best if the page that actually refers to the JS file cannot be cached or has very short caching time.

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

3 Comments

interesting thought, but in this case the main web page cannot be cached. Second thought.. read my response to Thomas Voracek
@David Dimitriov - What do you mean the main page "cannot be cached"? How do you know that or how are you assuring that? The new version of the page can't possibly request the old version of the JS file so clearly it's a caching issue somewhere. The question is where not if?
I am starting to think this is the problem. I need to look into this closer
1

I agree with jfriend00 about the webpage itself being cashed and thus requesting the old javascript version.

To prevent this, you can have the javascript file loaded by an ajax (Post) request, either requesting the server what is the accurate(latest) version number to download, or requesting the javascript itself and inserting it, e.g. in the head of the page.

Edit: see for example here

Comments

1

I make a quick AJAX request to the server for the version it expects them to have, then force them to refresh the page if the client's script is old.

Comments

0

Seems that proxy or some load balancer is serving old content instead of new. Also check IIS/webserver settings how are these files cached/expired.

You can check what is going on on the wire with tools like Fiddler.

1 Comment

while either of those could be the case, I feel like I personally would have experienced this myself before today at least once. It seems more like there is a situation where the browser itself is not requesting the new html page that references the JS file even though this is not technically allowed. But i don't know under what circumstances this could happen

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.