6

We have a single page app served as a single js file from index.html created using webpack. The name of the js file is hashed to burst the cache:

<script src="/app/assets/module.4ff4f6r342r23bfd26a.js"></script>

However I notice that browsers still cache the old version. Most likely this is happening because index.html got cached, and with it an old reference to the old module.js name. What is confusing, is that it seems like no one else is having this problem and i don't see a clear way to disable caching of index.html in webpack. What gives?

MK.
  • 33,605
  • 18
  • 74
  • 111
  • I think caching is controlled by the browser rather than webpack, in Chrome you can disable caching in **Developer Tools -> Network -> Disable cache** – paradite Jun 22 '16 at 04:10
  • html page can tell browser whether it should be cached or not. – MK. Jun 22 '16 at 04:47
  • No, html page cannot do that. I think you mean the server, which is sending the html page as the response to the browser. In that case, webpack is irrelevant as well, you need to configure your server accordingly. – paradite Jun 22 '16 at 05:26
  • of course html page can specify the caching rules: http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers – MK. Jun 22 '16 at 16:33
  • @MK Did you get a solution for this. I am running into same problem with angular service-worker – Sampat Mar 07 '18 at 01:49
  • My solution was to move out of the web development. True story. – MK. Mar 07 '18 at 21:47
  • @MK. you should add this line to your vita. – scipper May 02 '19 at 07:28
  • You could have just set ```cache-control: no-cache``` on the response header from your server, instead of moving out of web development :) – Selçuk Cihan May 02 '19 at 08:50
  • @SelçukCihan and how would I do that? Tell people controlling web server to add a special config just for my apps html page? Can you imagine how they would laugh at me. BTW life outside of web development is exactly as crappy as inside. – MK. May 02 '19 at 23:07
  • @scripper Trust me, most people will laugh at the resume of a guy with 20 yoe who is still an individual contributor even if he puts no intentional jokes there. – MK. May 02 '19 at 23:09
  • This is the most common practice - https://stackoverflow.com/questions/32414/how-can-i-force-clients-to-refresh-javascript-files#answer-52535465. You should disable caching on /index.html from your CDN settings. – Nigel Sheridan-Smith May 05 '22 at 06:38

0 Answers0