I'm diving into Progressive Web Applications lately. I've linked my manifest.json and sw.js like this:
In the index.html
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>static/manifest.json">
And in my main.js
if('serviceWorker' in navigator) {
const messaging = firebase.messaging()
navigator.serviceWorker.register('/static/sw.js').then((registration) => {
messaging.useServiceWorker(registration)
console.log('Service Worker registered')
}).catch((error) => {
console.log('Service Worker failed to register')
})
}
It looks like it works, but when I try to add the webapp to my homescreen using DevTools, it shows the following error: "Site cannot be installed: no matching service worker detected. You may need to reload the page, or check that the service worker for the current page also controls the start URL from the manifest"
After doing some research I found people say place the sw.js and manifest.json in the root of the project. But when I do, it won't link the files (when I put them in the static folder, it will link them). By the way, I'm using the standard Vue.js template.
Any suggestions how to fix this?