O
O
Oleg Sulima2018-09-12 13:23:03
Angular
Oleg Sulima, 2018-09-12 13:23:03

Angular2+: how to reliably deliver a new version of the application to the client bypassing the browser cache?

Hello. Question about putting a new version of the application on the server. How to notify the user so that he refreshes the page and at the same time the application is pulled up from the server, and not from the cache? Angular CLI gives a random name to the file when building and it seems like this should prevent the cache. Rarely, but it happens that the user has an old version. I can’t say for sure whether he reloaded the page or not, it’s hard to find the truth through tenth hands. Or if the user left a tab open while a new version came out...
From what I see: you can ask the server for the version number with each request, check with your own, and, if different, cancel the request, display a message to the user with a button that will reload the page without a cache, say using window.location.reload (true). In this method, I am confused by the moment when the user filled out a large form and lost everything. In principle, updates are released during non-working hours, so the number of such cases should be small. You can even try to cache everything and restore the model after the update if it has not changed much.
I understand that there is an option to use a service worker, it will pull up the new version, but here https://angular.io/guide/service-worker-communicat...it says "Doing this could break lazy-loading into currently running apps, especially if the lazy-loaded chunks use filenames with hashes, which change every version". It seems that at the same time it updates the page with updates.activateUpdate().then(() => document.location.reload());, so this phrase is not clear to me ... Did it somehow partially load there or what? why is everything broken? after all, after the update, the new main and all dependencies will be pulled up, and new names will already be known there ... Or is this phrase for the case when you do not refresh the page, but try to reload the SPA?
Maybe someone has experience in updating and you see pitfalls?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Demian Smith, 2018-09-12
@search

In Google Inbox, this is implemented through a pop-up button. If the application has detected a new version, then a non- intrusive message and a "reload" button are displayed. An elegant solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question