
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
next-service-worker
Advanced tools
A Next.js plugin that generates a Service Worker. Powered by Workbox.
A Next.js plugin that generates a Service Worker. Powered by Workbox.
A minimal wrapper around Workbox to quickly add a service worker to your Next.js site. Get precached pages and offline support out of the box.
Add this package to your project:
npm install next-service-worker
or yarn add next-service-worker
Update your next.config.js
:
+ const { serviceWorker } = require("next-service-worker");
+ const withServiceWorker = serviceWorker();
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
};
- module.exports = nextConfig;
+ module.exports = withServiceWorker(nextConfig);
(Optional): Add the generated service worker files to your .gitignore
:
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
...
+ # generated service worker (next-service-worker)
+ public/service-worker.js
+ public/workbox-*.js
That's it! A service worker that precaches all of your build's static assets will be generated. Static assets will be served from the service worker's cache instead of making network calls, speeding up your page views and enabling offline viewing 🙌.
next build && next start
.Application
tab and then clicking the Service Workers
tab.Name | Description | Type |
---|---|---|
registration.autoRegister |
Autoregister the service worker. If
Defaults to | boolean | undefined |
workbox |
Options passed to `worbox-build`. See all available configuration options [here](https://developer.chrome.com/docs/workbox/modules/workbox-build/)
Defaults to Note: | InjectManifestOptions | GenerateSWOptions |
Check out the next-service-worker-example. The only change from the default NextJS setup is the addition of next.config.js
!
You must serve your application over HTTPS in production environments. Service Workers must be served from the site's origin over HTTPS.
Some browsers special case localhost
, so this may not be necessary during local development. HTTPS is not handled by this library. You can use a reverse proxy like Nginx or Caddy if you want to setup HTTPS for local development.
The service worker origin constraint means that service workers can not control pages on a different subdomain. Eg mysite.com
can not be controlled by a service worker if that was served from a subdomain such as mycdn.mysite.com
. To learn more about how service workers work in general, read MDN's documentation.
PR's and issues welcomed! For more guidance check out CONTRIBUTING.md
See the project's MIT License.
FAQs
A Next.js plugin that generates a Service Worker. Powered by Workbox.
We found that next-service-worker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.