Renat Khabibulin
Renat Khabibulin

Reputation: 193

Force HTML template reload in Angular2

I am working on Angular2 project and got an issue that Chrome caches HTML templates. It is not a problem for the development since I can make cache to be ignored in Chrome Dev mode.

But it is a real pain for the customer and his users... I tried to add following to templateURL:

templateUrl: './pages/add-financial-deal.html?v=201610070907',

Updated URL is added into auto-generated JS but Chrome still uses cached JS even if I click Shift + F5. Checkout screenshot: http://screencast.com/t/bc2nf4zVcm

Is there any reliable way to get it working?

Thanks

Edit: Decmber 2nd

I have finally figured out what happening there. Despite the fact that I have added changes into TS (and auto-generated JS was also updated) Chrome is still loading file from in-memory cache - screencast.com/t/FGuaMXaKL . I have been waiting for 30 mins, but it still loads in-memory cached file. Is it intended behavior? How to avoid this?

Upvotes: 1

Views: 2141

Answers (1)

Renat Khabibulin
Renat Khabibulin

Reputation: 193

I have finally fixed an issue which was actually 2 issues:

  1. HTML templates were cached. This was fixed by adding extra parameter into template URL, like "template.html?v=201612041641"
  2. JS files were staying in Chrome in-memory cache. Despite the fact that it should be kinda fast cache JS were cached for hours and hours. And Ctrl/Shift + F5 does not affect in-memory cache. Also, I tried to set cache control to "no-store, no-cache" in root html page. Finally, I set extra header into IIS Response header option "Control-Cache:no-cache" and now it works. JS files are stored on hard drive Chtome store, 304 status is recieved and changed files are properly updated

Upvotes: 1

Related Questions