Closed jb-thery closed 2 weeks ago
I've noticed that each time we release a new version of our PWA, it initially tries to load the old index.html along with the addresses of the old scripts. When I manually click on "SkipWaiting" in Chrome DevTools, everything gets sorted out and the new content loads correctly.
Is this behavior a bug, or is there something I need to configure differently to ensure that the new index.html is loaded automatically after a release? Any guidance or advice on how to handle this would be greatly appreciated.
Review the cache headers, rebuilding the app will remove old assets: check https://vite-pwa-org.netlify.app/deployment/#cache-control
I also encounter this issue on localhost when I rebuild my PWA and run the vite preview script:
Failed to load resource: the server responded with a status of 404 (Not Found).
This occurs because the old index.html remains until I click on 'skipWaiting'.
do you have a link to the repo or deployed url (vercel)?
check also if you have Disabled cache
checked in dev tools
This caching issue on Vercel has been resolved by implementing the following configuration in the vercel.json file :
{
"headers": [
{
"source": "/(.*).html",
"headers": [
{
"key": "Cache-Control",
"value": "no-store"
}
]
},
{
"source": "/sw.js",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=0, must-revalidate"
}
]
},
{
"source": "/manifest.webmanifest",
"headers": [
{
"key": "Content-Type",
"value": "application/manifest+json"
}
]
},
{
"source": "/assets/(.*)",
"headers": [
{
"key": "Cache-Control",
"value": "max-age=31536000, immutable"
}
]
},
{
"source": "/(.*)",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
}
]
}
],
"rewrites": [
{
"source": "/(.*)",
"destination": "/index.html"
}
]
}
and click to purge data cache in Vercel dashboard
@jb-thery can you send a PR to the docs repo for Vercel entry in the deploy section? I have no idea about Vervel (I don't use it)
This is the file https://github.com/vite-pwa/docs/blob/main/deployment/vercel.md
You can fork docs repo to your GH account and then visit the page and click on edit this page at the bottom.
@userquin of course
Hello,
I'm experiencing a recurring issue with my React application using Vite PWA after each new deployment. The following error appears:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
This error surfaces in the Google Chrome Developer Tools. If I click on "Skip Waiting" or "Unregister" for the service worker and then refresh the page, everything starts working again.
Could this be a bug, or am I missing something in my configuration?
my package.json
Here is the configuration of my plugin in Vite:
My usage