I'm trying to use a Service worker in my app.
I've added @angular/pwa
,
registered the service worker:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/ngsw-worker.js', {
scope: '/'
}).then((registration) => {
console.log("Service worker OK!")
});
}
When i run Google Lighthouse on my local everything work perfect, and the site works in online mode, but whednI upload my app to server I recive an error in Lighthouse:
No manifest was fetched.
Do I use a wrong path?
manifest.json:
"start_url": "/index.html",
After adding the @angular/pwa
, double check these:
1.In your angular.json
file, under assets, add the manifest.json
, like below
"assets": [
"src/favicon.ico",
"src/assets",
"src/manifest.json"
],
2.Your manifest.json
file should be in the src/
directory, so src/manifest.json
3 Then in your ngsw-config.json
file, you should have this:
"files": [
"/favicon.ico",
"/index.html",
"/manifest.json"
],
Do the three steps above, and you're good to go.
That error means that your index.html
file doesn't tell browsers about the manifest. Add:
<link rel="manifest" href="manifest.json">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With