Workbox: Bad Precaching Response

Created on 8 Aug 2019  路  2Comments  路  Source: GoogleChrome/workbox

Library Affected:
workbox-build

Browser & Platform:
Google Chrome

Issue or Feature Request Description:
I am using Gridsome to create a web site and I am using the gridsome-plugin-pwa plugin. While it is setting up the service-worker it is returning a bad-precaching-response error. Is there an issue with my setup?

Here is the gridsome.config.js file where I use the plugin:

{
  use: 'gridsome-plugin-pwa',
  options: {
    title: 'Hummingbird Airsoft',
    startUrl: '/',
    display: 'standalone',
    statusBarStyle: 'default',
    manifestPath: 'manifest.json',
    serviceWorkerPath: 'service-worker.js',
    shortName: 'Gridsome',
    themeColor: '#666600',
    backgroundColor: '#ffffff',
    icon: 'public/favicon.ico' // must be supplied!
  }
}

Auto-generated service-worker:

service-worker.txt

Console error:

image

Git Repo: https://github.com/Matthew-Kanderka/hummingbird-Airsoft-Web/tree/develop

workbox-precaching

Most helpful comment

Precaching failed because you've got /assets/manifest/client.json in your precache manifest, but the request for that URL returned a HTTP 403 response code. Precaching will, by default, only succeed if all the requests for all the URLs in the precache manifest return a HTTP 200 (or are opaque responses).

The simplest approach would be to make sure that the URLs that are added to your precache manifest are exactly the URLs you want precached. It probably doesn't make sense to precache /assets/manifest/client.json if that URL is protected by authentication (which is normally what an HTTP 403 response indicates). Similarly, I see some URLs in the manifest of the service worker you provided that look like they're for 404.html. It doesn't make sense to precache those, either.

I am not familiar with gridsome-plugin-pwa plugin, but I would reach out to the authors of that project and explain that you need more control over filtering out URLs from the precache manifest it generates. The underlying Workbox build tools have support for options to do this, so hopefully it's just a question of passing those options through to Workbox.

(There are ways to configure Workbox's precaching to accept responses with 4xx or 5xx error codes, but that's a much more involved configuration that the plugin you're using would have to support, and honestly, it doesn't sound like these are responses that you _want_ precached.)

All 2 comments

Precaching failed because you've got /assets/manifest/client.json in your precache manifest, but the request for that URL returned a HTTP 403 response code. Precaching will, by default, only succeed if all the requests for all the URLs in the precache manifest return a HTTP 200 (or are opaque responses).

The simplest approach would be to make sure that the URLs that are added to your precache manifest are exactly the URLs you want precached. It probably doesn't make sense to precache /assets/manifest/client.json if that URL is protected by authentication (which is normally what an HTTP 403 response indicates). Similarly, I see some URLs in the manifest of the service worker you provided that look like they're for 404.html. It doesn't make sense to precache those, either.

I am not familiar with gridsome-plugin-pwa plugin, but I would reach out to the authors of that project and explain that you need more control over filtering out URLs from the precache manifest it generates. The underlying Workbox build tools have support for options to do this, so hopefully it's just a question of passing those options through to Workbox.

(There are ways to configure Workbox's precaching to accept responses with 4xx or 5xx error codes, but that's a much more involved configuration that the plugin you're using would have to support, and honestly, it doesn't sound like these are responses that you _want_ precached.)

Ok that makes sense but I don't understand where the /assets/manifest/client.json is coming from. I will still message the owner of the plugin. Thanks

Was this page helpful?
0 / 5 - 0 ratings