开发者

url rewriting to redirect to correct javascript file version

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 conf开发者_如何转开发used as to how it even going to make a difference to have a rewriting.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜