vite-plugin-pwa icon indicating copy to clipboard operation
vite-plugin-pwa copied to clipboard

non-precached-url: non-precached-url

Open Charles-1999 opened this issue 3 years ago • 6 comments

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.html file 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-url error 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

Charles-1999 avatar Aug 02 '22 12:08 Charles-1999

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$/] 
},

userquin avatar Aug 02 '22 12:08 userquin

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$/] 
},

but i have not using SSR

Charles-1999 avatar Aug 02 '22 12:08 Charles-1999

it is any effect if i get this error (non-precached-url: non-precached-url)?

Charles-1999 avatar Aug 02 '22 12:08 Charles-1999

image @userquin

this is the normal logic, exclude the html file.

but if I precache the html file, the redirect will not take effect.

Charles-1999 avatar Aug 02 '22 13:08 Charles-1999

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

userquin avatar Aug 02 '22 13:08 userquin

https://github.com/antfu/vite-plugin-pwa/issues/120#issuecomment-1202579983

userquin avatar Aug 02 '22 13:08 userquin