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

后端 未结 30 4344
青春惊慌失措
青春惊慌失措 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 06:14

    This question is super old, and appears first thing when anybody googles this issue. This is not an answer to the question the way op wants it, instead is an answer to devs with this problem while developing and testing. And i can't post a new question on this topic since will be marked as duplicate.

    Like many others, i just wanted to remove caching briefly.

    "keep caching consistent with the file" .. its way too much hassle ..

    Generally speaking, I don't mind loading more - even loading again files which did not change - on most projects - is practically irrelevant. While developing an app - we are mostly loading from disk, on localhost:port - so this increase in network traffic issue is not a deal breaking issue.

    Most small projects are just playing around - they never end-up in production. so for them you don't need anything more..

    As such if you use Chrome Dev Tools, you can follow this disable caching approach like in the image below:

    And if you have firefox caching issues:

    Do this only in development, you also need a mechanism to force reload for production, since your users will use old cache invalidated modules if you update your app frequently and you don't provide a dedicated cache sync mechanism like the ones described in the answers above.

    Yes, this info is already in previous answers but i still needed to do a google search to find it.

    Hopefully this answer is very clear and now you don't need to.

提交回复
热议问题