vite-plugin-pwa
vite-plugin-pwa copied to clipboard
non-precached-url: non-precached-url
Sorry to pickup an old thread here, however this is causing some confusion for me.
I'm using Vite to SSR a page, however the
index.htmlfile gets added to the client bundle even though it's not served by users. My server returns the HTML, however with the index.html file being cached, it's returning the version of my html which is missing things (e.g. I replace<!-- app-head -->on the server to add metadata). The SW kicks in and serves the cached file instead of the server.If I add the html file to the ignore glob, I get the
non-precached-url: non-precached-urlerror described here.
@userquin I have got a similar problem, how can i exclude the html file.
Originally posted by @Charles-1999 in https://github.com/antfu/vite-plugin-pwa/issues/120#issuecomment-1202392339
if you have SSR for your entry point, add an 404.html page and use it as the navigationFallback in the dev options. If the entry point shouldn't be added to the pwa, just exclude it using 404.html only in the allowlist (workbox.navigateFallbackAllowlist if using generateSW strategy).
EDIT (there is no navigateFallback in dev options ;) ):
// vite.config.[jt]s
workbox: {
navigateFallback: '404.html',
navigateFallbackAllowlist: [/\/404.html$/]
},
if you have SSR for your entry point, add an 404.html page and use it as the
navigationFallbackin the dev options. If the entry point shouldn't be added to the pwa, just exclude it using 404.html only in theallowlist(workbox.navigateFallbackAllowlistif usinggenerateSWstrategy).EDIT (there is no
navigateFallbackin dev options ;) ):// vite.config.[jt]s workbox: { navigateFallback: '404.html', navigateFallbackAllowlist: [/\/404.html$/] },
but i have not using SSR
it is any effect if i get this error (non-precached-url: non-precached-url)?
@userquin
this is the normal logic, exclude the html file.
but if I precache the html file, the redirect will not take effect.
Try adding previous config using index.html instead 404.html, this will instruct the sw to only cache the entry point.
If still not working, provide a repro, any example in this repo (in examples folder) are working without the error.
EDIT: try adding the credentials entry to the pwa configuration: https://vite-plugin-pwa.netlify.app/guide/faq.html#web-app-manifest-and-401-status-code-unauthorized
https://github.com/antfu/vite-plugin-pwa/issues/120#issuecomment-1202579983