Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WorkboxError non-precached-url index.html #120

Closed
jonian opened this issue Aug 21, 2021 · 15 comments
Closed

WorkboxError non-precached-url index.html #120

jonian opened this issue Aug 21, 2021 · 15 comments

Comments

@jonian
Copy link

jonian commented Aug 21, 2021

Hi, thank you for this plugin.

I'm getting the error below when running the app with vite preview and in production. The app source code is available at https://github.com/jonian/awmonitor and the production link is https://awmonitor.netlify.app.

WorkboxError.js:28 Uncaught (in promise) non-precached-url: non-precached-url :: [{"url":"index.html"}]
    at x.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:12967)
    at Object.createHandlerBoundToURL (http://localhost:5000/workbox-a59a8da5.js:1:14597)
    at http://localhost:5000/sw.js:1:10085
    at http://localhost:5000/sw.js:1:695
s @ WorkboxError.js:28
createHandlerBoundToURL @ PrecacheController.js:276
(anonymous) @ createHandlerBoundToURL.js:29
(anonymous) @ sw.js:486
(anonymous) @ sw.js:1
@userquin
Copy link
Member

@jonian can you try removing ?standalone=true from the start_url with vite preview?.

@userquin
Copy link
Member

The problem is that routes are not added to the sw precache, you need to add them manually, I'll push changes to my fork and make a PR to your repo.

You can see this comment antfu-collective/vitesse#159 for an explanation.

@userquin
Copy link
Member

userquin commented Aug 21, 2021

Well, the problem is on your workbox.globPatterns entry: you need to include all, it is exclusive, that is, if you include this entry, you MUST add all your patterns, not only font assets: in your case, you are not including js and css assets and index.html page.

Since you are using vite, all entries under assets directory will be included, you don't need to add them again.

Just remove the workbox entry from your configuration:

imagen

imagen

You also need to add all red entries shown bellow to make it work offline, it is working, but some images missing:

imagen

@jonian
Copy link
Author

jonian commented Aug 21, 2021

Thanks for the quick response and the help @userquin

@userquin
Copy link
Member

@jonian I will add some entry on docs when using globaPatterns and some other similar entries from workbox and injectManifest to avoid this type of problems...

@jonian
Copy link
Author

jonian commented Aug 21, 2021

Thank you again @userquin, that will be really helpful.

jonian added a commit to jonian/awmonitor that referenced this issue Aug 21, 2021
@jonian
Copy link
Author

jonian commented Aug 21, 2021

You also need to add all red entries shown bellow to make it work offline, it is working, but some images missing

@userquin there are no images missing, they are the fonts the app uses from @iconscout/unicons. If I remove the font entries from the workbox config, the fonts are not available in offline mode. If I use the config below, everything works as expected in offline mode.

workbox: {
  globPatterns: [
    '*/*.*',
    '*.*'
  ]
}

Without the workbox option in offline mode:

Screenshot from 2021-08-21 19-41-39

With the workbox option above in offline mode:

Screenshot from 2021-08-21 19-38-51

@userquin
Copy link
Member

@jonian read this entry to configure properly your external fonts: https://vite-plugin-pwa.netlify.app/workbox/generate-ws.html#cache-external-resources

Basically you need to add crossorigin and then add runtimeCaching for fonts urls. I suggest you to add also dns-prefetch links.

@userquin
Copy link
Member

@jonian I have included a warning on Static Assets Handling entry: just go to https://vite-plugin-pwa.netlify.app/guide/static-assets.html and wait for prompt for update and then click reload button.

@Ehesp
Copy link

Ehesp commented Jul 19, 2022

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.

@Charles-1999
Copy link

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.

@Ehesp
Copy link

Ehesp commented Aug 2, 2022

I use this config now - not sure if it's fully correct but seems to be working:

{
  strategies: 'generateSW',
  workbox: {
    // Only precache these files - html should be excluded
    globPatterns: ['**/*.{js,css}'],

    // Don't fallback on document based (e.g. `/some-page`) requests
    // Even though this says `null` by default, I had to set this specifically to `null` to make it work
    navigateFallback: null,
}

This seems to remove the generated config containing the index.html, which is then just handled by the server.

@userquin
Copy link
Member

userquin commented Aug 2, 2022

@Ehesp you're right, the default value when undefined is configured by the options module with index.html, so you need to set it to null.

@Ehesp
Copy link

Ehesp commented Aug 2, 2022

I made a quick PR to update the type docs: GoogleChrome/workbox#3106

@jwandekoken
Copy link

I use this config now - not sure if it's fully correct but seems to be working:

{
  strategies: 'generateSW',
  workbox: {
    // Only precache these files - html should be excluded
    globPatterns: ['**/*.{js,css}'],

    // Don't fallback on document based (e.g. `/some-page`) requests
    // Even though this says `null` by default, I had to set this specifically to `null` to make it work
    navigateFallback: null,
}

This seems to remove the generated config containing the index.html, which is then just handled by the server.

Thanks. I was having the same issue here, this config. helped out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants