1

Currently, I have angular 2 app running and working great on a shared web hosting.

I'm using angular 2 cli and I upload my dist folder whenever I make changes.

When I access my app after making changes and uploadidng the new dist content, I see the old version - without any changes. When I Accessing the app from Spy Mode (CTRL+SHIFT+N) in Chrome, I see the new version.

I assume that need to delete the cache every time making changes to angular 2 app, so the browser will reload the new version.

Is there any way to make it reload the app whenever I'm making changes and uploading a new app version?

I do not wish to make a notice to my visitors to refresh the browser cache in order to see a new version..

TheUnreal
  • 23,434
  • 46
  • 157
  • 277

2 Answers2

1

Add a version number to the URL and make the client check the version regularly and make it redirect itself to the new URL when it detects a new version.

See also htaccess - How to force the client's browser to clear the cache?

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • Thanks. It looked good at first, but then I was thinking about making a new URL for each upgrade - and it's not a great solution. If google already indexes my website URL - it will have to index each new url every time I'm upgrading which makes this solution really bad for SEO. Although it gave me some idea.. will adding a version number to the main,js file and updating index.html with the new file route may work? *edit*: Seem like there is no reference to the main.js in the` index.html` \: – TheUnreal Aug 20 '16 at 12:19
  • AFAIK adding some query parameter also makes the browser to reload and keeps the URL the same. – Günter Zöchbauer Aug 20 '16 at 15:25
0

I found this as a good solution. He has a script that is run on every release that creates a version.json that is checked every so often and if that file changes it reloads the app (or whatever you want it to do).

https://blog.nodeswat.com/automagic-reload-for-clients-after-deploy-with-angular-4-8440c9fdd96c

Scot
  • 165
  • 2
  • 14