Gathering detailed insights and metrics for gatsby-plugin-offline
Gathering detailed insights and metrics for gatsby-plugin-offline
Gathering detailed insights and metrics for gatsby-plugin-offline
Gathering detailed insights and metrics for gatsby-plugin-offline
The best React-based framework with performance, scalability and security built in.
npm install gatsby-plugin-offline
Typescript
Module System
Min. Node Version
Node Version
NPM Version
29
Supply Chain
53.8
Quality
80
Maintenance
50
Vulnerability
89.4
License
gatsby-source-shopify@9.0.0
Published on 07 Jan 2025
gatsby-link@5.14.1
Published on 07 Jan 2025
gatsby-source-contentful@8.15.0
Published on 07 Jan 2025
v5.14.0
Published on 06 Nov 2024
gatsby-source-shopify@8.13.2
Published on 28 Oct 2024
gatsby-source-wordpress@7.13.5 and 6 more...
Published on 28 Oct 2024
JavaScript (59%)
TypeScript (38.63%)
CSS (1.05%)
HTML (0.69%)
MDX (0.44%)
Shell (0.12%)
Dockerfile (0.03%)
PHP (0.02%)
EJS (0.01%)
Total Downloads
41,456,224
Last Day
8,457
Last Week
43,027
Last Month
197,276
Last Year
3,224,594
55,655 Stars
21,720 Commits
10,304 Forks
727 Watching
473 Branches
3,984 Contributors
Minified
Minified + Gzipped
Latest Version
6.14.0
Package Id
gatsby-plugin-offline@6.14.0
Unpacked Size
94.40 kB
Size
19.78 kB
File Count
12
NPM Version
lerna/3.22.1/node@v20.11.1+arm64 (darwin)
Node Version
20.11.1
Publised On
06 Nov 2024
Cumulative downloads
Total Downloads
Last day
-0.8%
8,457
Compared to previous day
Last week
-15.7%
43,027
Compared to previous week
Last month
3.3%
197,276
Compared to previous month
Last year
-38%
3,224,594
Compared to previous year
Adds drop-in support for making a Gatsby site work offline and more resistant to bad network connections. It uses Workbox Build to create a service worker for the site and loads the service worker into the client.
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.
npm install gatsby-plugin-offline
1// In your gatsby-config.js 2plugins: [`gatsby-plugin-offline`]
In gatsby-plugin-offline
3.x, the following options are available:
precachePages
lets you specify pages whose resources should be precached by the service worker, using an array of globs. For example:
1plugins: [ 2 { 3 resolve: `gatsby-plugin-offline`, 4 options: { 5 precachePages: [`/about-us/`, `/projects/*`], 6 }, 7 }, 8]
Note: while essential resources of specified pages will be precached, such as JavaScript and CSS, non-essential resources such as fonts and images will not be included. Instead, these will be cached at runtime when a user visits a given page that includes these resources.
appendScript
lets you specify a file to be appended at the end of the generated service worker (sw.js
). For example:
1plugins: [ 2 { 3 resolve: `gatsby-plugin-offline`, 4 options: { 5 appendScript: require.resolve(`src/custom-sw-code.js`), 6 }, 7 }, 8]
1// show a notification after 15 seconds (the notification 2// permission must be granted first) 3setTimeout(() => { 4 self.registration.showNotification("Hello, world!") 5}, 15000) 6 7// register a custom navigation route 8const customRoute = new workbox.routing.NavigationRoute(({ event }) => { 9 // ... 10}) 11workbox.routing.registerRoute(customRoute)
debug
specifies whether Workbox should show debugging output in the browser console at runtime. When undefined, defaults to showing debug messages on localhost
only.
workboxConfig
allows you to override the default Workbox options - see Overriding Workbox configuration. For example:
1plugins: [ 2 { 3 resolve: `gatsby-plugin-offline`, 4 options: { 5 workboxConfig: { 6 importWorkboxFrom: `cdn`, 7 }, 8 }, 9 }, 10]
To upgrade from 2.x to 3.x, move any existing options into the workboxConfig
option. If you haven't specified any options, you have nothing to do.
For example, here is a 2.x config:
1plugins: [ 2 { 3 resolve: `gatsby-plugin-offline`, 4 options: { 5 importWorkboxFrom: `cdn`, 6 }, 7 }, 8]
Here is the equivalent 3.x config:
1plugins: [ 2 { 3 resolve: `gatsby-plugin-offline`, 4 options: { 5 workboxConfig: { 6 importWorkboxFrom: `cdn`, 7 }, 8 }, 9 }, 10]
In version 3, Workbox is also upgraded to version 4 so you may need to update your workboxConfig
if any of those changes apply to you. Please see the docs on Google Developers for more information.
When adding this plugin to your gatsby-config.js
, you can use the option workboxConfig
to override the default Workbox config. To see the full list of options, see this article on Google Developers.
The default workboxConfig
is as follows. Note that some of these options are configured automatically, e.g. globPatterns
. If you're not sure about what all of these options mean, it's best to leave them as-is - otherwise, you may end up causing errors on your site, causing old files to be remain cached, or even breaking offline support.
1const options = { 2 importWorkboxFrom: `local`, 3 globDirectory: rootDir, 4 globPatterns, 5 modifyURLPrefix: { 6 // If `pathPrefix` is configured by user, we should replace 7 // the default prefix with `pathPrefix`. 8 "/": `${pathPrefix}/`, 9 }, 10 cacheId: `gatsby-plugin-offline`, 11 // Don't cache-bust JS or CSS files, and anything in the static directory, 12 // since these files have unique URLs and their contents will never change 13 dontCacheBustURLsMatching: /(\.js$|\.css$|static\/)/, 14 runtimeCaching: [ 15 { 16 // Use cacheFirst since these don't need to be revalidated (same RegExp 17 // and same reason as above) 18 urlPattern: /(\.js$|\.css$|static\/)/, 19 handler: `CacheFirst`, 20 }, 21 { 22 // page-data.json files, static query results and app-data.json 23 // are not content hashed 24 urlPattern: /^https?:.*\/page-data\/.*\.json/, 25 handler: `StaleWhileRevalidate`, 26 }, 27 { 28 // Add runtime caching of various other page resources 29 urlPattern: 30 /^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, 31 handler: `StaleWhileRevalidate`, 32 }, 33 { 34 // Google Fonts CSS (doesn't end in .css so we need to specify it) 35 urlPattern: /^https?:\/\/fonts\.googleapis\.com\/css/, 36 handler: `StaleWhileRevalidate`, 37 }, 38 ], 39 skipWaiting: true, 40 clientsClaim: true, 41}
If you want to remove gatsby-plugin-offline
from your site at a later point,
substitute it with gatsby-plugin-remove-serviceworker
to safely remove the service worker. First, install the new package:
1npm install gatsby-plugin-remove-serviceworker 2npm uninstall gatsby-plugin-offline
Then, update your gatsby-config.js
:
1 plugins: [ 2- `gatsby-plugin-offline`, 3+ `gatsby-plugin-remove-serviceworker`, 4 ]
This will ensure that the worker is properly unregistered, instead of leaving an outdated version registered in users' browsers.
Gatsby offers great SEO capabilities and that is no different with gatsby-plugin-offline
. However, you shouldn't think that Gatsby doesn't serve HTML tags anymore when looking at your source code in the browser (with Right click
=> View source
). View source
doesn't represent the actual HTML data since gatsby-plugin-offline
registers and loads a service worker that will cache and handle this differently. Your site is loaded from the service worker, not from its actual source (check your Network
tab in the DevTools for that).
To see the HTML data that crawlers will receive, run this in your terminal:
on Windows (using powershell):
1Invoke-WebRequest https://www.yourdomain.tld | Select -ExpandProperty Content
on Mac OS/Linux:
1curl https://www.yourdomain.tld
Alternatively you can have a look at the /public/index.html
file in your project folder.
Server logs (like from Netlify analytics) may show a large number of pageviews to a route like /offline-plugin-app-shell-fallback/index.html
, this is a result of gatsby-plugin-offline
adding an app shell to the page. The app shell is a minimal amount of user interface that can be cached offline for reliable performance loading on repeat visits. The shell can be loaded from the cache, and the content of the site loaded into the shell by the service worker.
If using this plugin with gatsby-plugin-manifest
you may find that your icons are not cached.
In order to solve this, update your gatsby-config.js
as follows:
1// gatsby-config.js 2{ 3 resolve: 'gatsby-plugin-manifest', 4 options: { 5 icon: 'icon.svg', 6 cache_busting_mode: 'none' 7 } 8}, 9{ 10 resolve: 'gatsby-plugin-offline', 11 options: { 12 workboxConfig: { 13 globPatterns: ['**/icon-path*'] 14 } 15 } 16}
Updating cache_busting_mode
is necessary. Otherwise, workbox will break while attempting to find the cached URLs.
Adding the globPatterns
makes sure that the offline plugin will cache everything.
Note that you have to prefix your icon with icon-path
or whatever you may call it
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no dangerous workflow patterns detected
Reason
22 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
SAST tool is not run on all commits -- score normalized to 8
Details
Reason
Found 12/16 approved changesets -- score normalized to 7
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
85 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn Moregatsby-plugin-offline-next
Gatsby plugin which sets up a site to be able to run offline
@sekmet/gatsby-plugin-offline
Gatsby plugin which sets up a site to be able to run offline with push notification support
gatsby-plugin-appsync
This plugin provides offline support and non-offline support with AWS Appysnc.
gatsby-plugin-sw
Similar to gatsby-plugin-offline but you can customize the service worker (e.g. add notifications).