I have been reading all the threads on here regarding PWA deployment and none of the fixes are working.
I have a Python web app hosted on python anywhere and would like to deploy it as a PWA.
When I add my manifest.json to my root folder and reference this in the index.html file with the below:
<link rel="manifest" href="./manifest.json" />
i get the following error:
If I then move my Manifest file to my /assets folder and update my href in my index.html to:
<link rel="manifest" href="/assets/manifest.json" />
my manifest starts working - then I get an error of service worker not being matched:
Service worker error in Manifest
I tested my service worker in my root folder, same issue as the manifest above, I have moved my service worker to my /assets/ folder and set my index.html file to read this:
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', ()=> {
navigator
.serviceWorker
.register('/assets/sw01.js')
.then(()=>console.log("Ready."))
.catch(()=>console.log("Err..."));
});
}
</script>
My service worker shows it is running in chrome:
However my manifest shows no matching service worker.
additional information:
Any assistance would be greatly appreciated!
This is a service worker scope issue, along the lines of Understanding Service Worker scope.
If you serve you service worker from /assets/sw01.js
, it can't control /
. You should move your service worker to the top-level, like /sw01.js
.