Skip to content
Similar to gatsby-plugin-offline but you can customize the service worker (e.g. add notifications).
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
app-shell.js
gatsby-browser.js
gatsby-node.js
get-resources-from-html.js
index.js
package.json
yarn.lock

README.md

gatsby-plugin-sw

Tested only on linux with gatsby v2

Add support for making a Gatsby site work offline and more resistant to bad network connections. It creates a service worker using workboxBuild.injectManifest.

If you're using this plugin with gatsby-plugin-manifest (recommended) this plugin should be listed after that plugin so the manifest file can be included in the service worker.

Install

npm install --save gatsby-plugin-sw

How to use

// In your gatsby-config.js
plugins: [
  {
    resolve: 'gatsby-plugin-sw',
    options: {
      swPath: 'src/utils/my-service-worker.js', // Default to 'src/sw.js'
    },
  },
]
// In your service worker e.g. src/sw.js

// Required stuff
importScripts(
  'https://storage.googleapis.com/workbox-cdn/releases/3.4.1/workbox-sw.js'
)

// The plugin will pass the files to cache here
workbox.precaching.precacheAndRoute([])

// Another things
self.addEventListener('push', () => {
  // ...
})

Options

For now the only option avaible is swPath and it's the location of your service worker file.

You can’t perform that action at this time.