Last active
December 13, 2019 09:08
-
-
Save pravnkay/5554dad945f91b0217ea5fcd9f18427e to your computer and use it in GitHub Desktop.
howto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As I figured out, this question is really only related to beginners in PWA, which don't know that you can (and need) to configure PWA for achieving this. If you feel addressed now (and using VueJS) remember: | |
To automatically download the new content, you need to configure PWA. In my case (VueJS) this is done by creating a file vue.config.js in the root directory of my project (On the same level as package.json). | |
Inside this file you need this: | |
module.exports = { | |
pwa: { | |
workboxOptions: { | |
skipWaiting: true | |
} | |
} | |
} | |
Which will automatically download your new content if detected. However, the content won't be displayed to your client yet, since it needs to refresh after downloading the content. I did this by adding window.location.reload(true) to registerServiceWorker.js in my src/ directory: | |
updated () { | |
console.log('New content is available: Please refresh.') | |
window.location.reload(true) | |
}, | |
Now, if the Service Worker detects new content, it will download it automatically and refresh the page afterwards. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment