Service worker

Explore the Service worker preset with Nitro to push the boundaries of Nuxt rendering to the edge.

Service worker - 图1 Can be used for edge-side rendering

Service worker - 图2 No dependency on Node.js

Service worker - 图3 No Node.js environment and features

Service worker - 图4

Back to presets list.

Deployment as a service worker has some limitations since SSR code is not running in Node.js environment but pure JavaScript.

Usage

You can use the Nuxt config to explicitly set the preset to use:

nuxt.config.js|ts

  1. export default {
  2. nitro: {
  3. 'browser-worker'
  4. }
  5. }

Or directly use the NITRO_PRESET environment variable when running nuxt build:

  1. NITRO_PRESET=worker npx nuxt build

Entry point

The worker preset produces a service worker that can provide full HTML rendering within a worker context (for example Cloudflare Workers). It registers appropriate handlers for fetch, install and activate.

For more information, you can check out the source code.