1

I have web-site build with angular that is hosted on cloudflare. When I push new version of application on server, I see from dev computer that browser uses old (from disk-cache) version of files. Because it uses previous versions of index.html, runtime, pollyfile and main js code files.

When getting file, I dont see any header from cloudflare instructing cache stail time on browser. Browser Cache TTL is set to default 4h. Also header expect-ct has max-age=604800, but as I read that is for certificate. I also used purge-cache option on cloudflare ('Purge Everything' is the button).

It seams to me that old version of index.html (the first file that is loaded in Angular application) is cached locally and because of that everything falls apart. How to prevent this?

  • This answer may solve your problem https://stackoverflow.com/questions/39647810/how-to-prevent-browser-cache-on-angular-2-site – pastaleg Sep 24 '20 at 09:41
  • Use Ctrl + F5 instead of F5 to refresh the page with clearing the cache. – Anduin Xue Sep 24 '20 at 09:59
  • @Anduin I can tell clients to press F5 to load newer version of application. I need it in code. – usernumber124153 Sep 24 '20 at 11:26
  • @pastaleg I use build --prod and from what I've seen it adds to hash codes on end of file names. On all, except index.html. – usernumber124153 Sep 24 '20 at 11:28
  • 1
    @usernumber124153 cool. The hash on top of the file names will indicate to the browsers that scripts and images are new, and should be fetched instead of loaded from cache. The index.html file cannot have such a hash. To handle cached html, see this answer for header setup and scroll down to HTML4 section to see the meta tags https://stackoverflow.com/questions/49547/how-do-we-control-web-page-caching-across-all-browsers – pastaleg Sep 24 '20 at 11:37
  • @pastaleg Yes, the answer is web-server should set that header. I need it for nginx so I googled it. Thanks – usernumber124153 Sep 25 '20 at 12:54

1 Answers1

0

Web server should set header 'cache-control' value. As @pastaleg said you can see question How do we control web page caching, across all browsers? for most web-servers. You can find answer for nginx on the web.