How to force the browser to reload cached CSS/JS files?

后端 未结 30 4284
青春惊慌失措
青春惊慌失措 2020-11-21 05:49

I have noticed that some browsers (in particular, Firefox and Opera) are very zealous in using cached copies of .css and .js files, even be

30条回答
  •  天涯浪人
    2020-11-21 05:53

    You can just put ?foo=1234 at the end of your css / js import, changing 1234 to be whatever you like. Have a look at the SO html source for an example.

    The idea there being that the ? parameters are discarded / ignored on the request anyway and you can change that number when you roll out a new version.


    Note: There is some argument with regard to exactly how this affects caching. I believe the general gist of it is that GET requests, with or without parameters should be cachable, so the above solution should work.

    However, it is down to both the web server to decide if it wants to adhere to that part of the spec and the browser the user uses, as it can just go right ahead and ask for a fresh version anyway.

提交回复
热议问题