2021-06-14 12:31:30 +00:00
# Service worker
2021-10-11 17:18:38 +00:00
Explore the Service worker preset with Nitro to push the boundaries of Nuxt rendering to the edge.
2021-06-14 12:31:30 +00:00
2021-10-11 17:18:38 +00:00
::list
2021-10-29 11:26:01 +00:00
2021-10-11 17:18:38 +00:00
- Can be used for edge-side rendering
- No dependency on Node.js
- No Node.js environment and features
::
::alert{icon=IconPresets}
2022-04-06 05:56:08 +00:00
Back to [presets list ](/guide/deployment/presets ).
2021-10-11 17:18:38 +00:00
::
::alert{type=warning}
2021-06-14 12:31:30 +00:00
Deployment as service worker has some limitations since SSR code is not running in Node.js environment but pure JavaScript.
2021-10-11 17:18:38 +00:00
::
## Usage
2022-04-06 05:56:08 +00:00
You can use the [Nuxt config ](/guide/directory-structure/nuxt.config ) to explicitly set the preset to use:
2021-10-11 17:18:38 +00:00
2021-10-29 11:26:01 +00:00
```js [nuxt.config.js|ts]
2021-10-11 17:18:38 +00:00
export default {
nitro: {
2022-04-07 11:28:04 +00:00
'browser-worker'
2021-10-11 17:18:38 +00:00
}
}
```
Or directly use the `NITRO_PRESET` environment variable when running `nuxt build` :
```bash
NITRO_PRESET=worker npx nuxt build
```
2021-06-14 12:31:30 +00:00
2021-10-29 11:26:01 +00:00
## Entry point
2021-06-14 12:31:30 +00:00
2022-04-06 05:56:08 +00:00
The worker preset produces a service worker that can provide full HTML rendering within a worker context (for example [Cloudflare Workers ](/guide/deployment/cloudflare )). It registers appropriate handlers for `fetch` , `install` and `activate` .
2021-06-14 12:31:30 +00:00
2022-04-14 13:38:47 +00:00
For more information you can see the [source code ](https://github.com/unjs/nitro/blob/main/src/presets/service-worker.ts ).