Skip to content

Commit 357b720

Browse files
docs(guide): add information on the usage of publicPath in web workers (#7839)
1 parent eef90bf commit 357b720

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/content/guides/web-workers.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,18 @@ const worker = new Worker(new URL("./worker.js", import.meta.url));
105105
worker.postMessage({ publicPath: globalThis.__MY_GLOBAL_PUBLIC_PATH_VAR__ });
106106
```
107107
108+
**When to use this:**
109+
110+
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).
111+
112+
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.
113+
114+
> 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.
115+
108116
## Node.js
109117
118+
This section describes using Web Workers in a Node.js environment via the `worker_threads` module.
119+
110120
Similar syntax is supported in Node.js (>= 12.17.0):
111121
112122
```js

0 commit comments

Comments
 (0)