Self updating web page
If a new version is discovered, the event will be fired.If this event is fired, we then need to check if a new service worker has been acquired and assign it to a new variable as we will be using this at a later stage.Have you ever been on a website and noticed a popup notification that suggests that there is a new version of the site available?
It got me wondering how I could build something a little similar and it turns out that it is a little tricker than it seems - but it is not impossible!
Now that we have determined that there is a new service worker waiting to be installed, we can then display a notification at the bottom of our page notifying the user that there is a new version available.
If you remember the diagram earlier in this article, you’ll remember that we still need to complete steps 3 & 4 in order for our new service worker to start controlling the page.
This article is a bit of a lengthy beast, so strap in tight and get comfy!
In this example, I am going to use a very basic web page that consists of three assets: In the web page above, you may notice that I’ve added standard boilerplate code for a web page and the registering of a service worker. Next, create a file and call it and add the following code: image, it will retrieve it from cache and instantly display it to the user.