Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/content/guides/web-workers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ self.onmessage = ({ data: { publicPath, ...otherData } }) => {
}

// rest of the worker code
}
};
```
**app.js**
Expand All @@ -77,8 +77,18 @@ const worker = new Worker(new URL('./worker.js', import.meta.url));
worker.postMessage({ publicPath: window.__MY_GLOBAL_PUBLIC_PATH_VAR__ });
```
**When to use this:**
This pattern is only required when a worker needs to load additional chunks and the asset base URL is determined at runtime (for example, when using a CDN or a multi-domain deployment).
Since workers run in an isolated global scope, the automatically detected public path may differ from the one used by the main thread. In such cases, the public path (`__webpack_public_path__`) must be explicitly passed to the worker and set inside the worker runtime.
> Note: This is an advanced use case. If your worker does not load additional chunks or your assets are served from a static, same-origin path, you typically do not need to set `__webpack_public_path__` manually.
## Node.js
This section describes using Web Workers in a Node.js environment via the `worker_threads` module.
Similar syntax is supported in Node.js (>= 12.17.0):
```js
Expand Down
Loading