0

I recently read on Meta about some browser not flushing their cache even after reading a script url of this form

myscript.js?v=1234

so to go around the problem i am thinking about implementing a solution i also read but without any details given to it. something like myscript-1234.js and reroute to the actual correct file, but i have a doubt now. Should i rewrite that url to myscript.js or to myscript.js?v=1234 ? I am actually confused as to how it even going to make a difference to have a rewriting.

1 Answer 1

1

Your rewriting should not redirect to any other URL (which would the be fetched by the browser), but should be "internal" on your server.

What I mean is that when receiving a request for "myscript-1234.js", your server should instead serve the content of the myscript.js file ; which will always be the last version.

In the end :

  • For the client the is a different URL each time you update the file on the server : myscript-1234.js, myscript-1235.js, myscript-1236.js, ...
    • This is why the browser will try to re-fetch the file from the server : as it's not the same name, it will not have the file in cache
  • But, for the server, there is always one and only one file : myscript.js
  • And you're using some "rewrite" rule so thr server just removes the -XYZ portion of the file name before trying to read it from disk.
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for your help! it makes sense! i just finished implementing it!

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.