Hello , I have developed the PWA using ionic 2 … When I am trying to compile the code to upload it on the server and enabling the service worker in index.html file.
My problem is that the changes are not reflected in when I browse the application in my device . How would I get the updated content after compiling the code ?
Depending on when you started your app, the service worker might still use the self.toolbox.cacheFirst strategy. If that’s the case, change it to self.toolbox.fastest. See this PR and the forum posts linked there for further discussion.
My service worker looks like this, after making the changes . Let me know what need be changed …
/**
* Check out https://googlechrome.github.io/sw-toolbox/ for
* more info on how to use sw-toolbox to custom configure your service worker.
*/
'use strict';
importScripts('./build/sw-toolbox.js');
self.toolbox.options.cache = {
name: 'ionic-cache-v1'
};
// pre-cache our key assets
self.toolbox.precache(
[
'./build/main.js',
'./build/vendor.js',
'./build/main.css',
'./build/polyfills.js',
'index.html',
'manifest.json'
]
);
// dynamically cache any other local assets
//self.toolbox.router.any('/*', self.toolbox.cacheFirst);
self.toolbox.router.any('/*', self.toolbox.fastest);
// for any other requests go to the network, cache,
// and then only use that cached resource if your user goes offline
self.toolbox.router.default = self.toolbox.networkFirst;
Also, this can be due to the CDN that you are using.
When deploying SPAs, it’s a well-known issue how do you tell the CDN to update the contents after a new version has been uploaded.
There are mainly two ways of doing this:
By evicting the cache of all servers in the CDN.
By using a versioned file name in your deployment.
The most effective is the second, and for that there are several techniques, being the most convenient using a webpack plugin to instruct webpack to version the output files.