Skip to content

Commit fb0aa69

Browse files
docs: improve clarity around publicPath usage in workers
1 parent a2a4d07 commit fb0aa69

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/content/guides/web-workers.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ self.onmessage = ({ data: { publicPath, ...otherData } }) => {
6767
}
6868

6969
// rest of the worker code
70-
}
70+
};
7171
```
7272
7373
**app.js**
@@ -77,8 +77,18 @@ const worker = new Worker(new URL('./worker.js', import.meta.url));
7777
worker.postMessage({ publicPath: window.__MY_GLOBAL_PUBLIC_PATH_VAR__ });
7878
```
7979
80+
**When to use this:**
81+
82+
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).
83+
84+
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.
85+
86+
> 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.
87+
8088
## Node.js
8189
90+
This section describes using Web Workers in a Node.js environment via the `worker_threads` module.
91+
8292
Similar syntax is supported in Node.js (>= 12.17.0):
8393
8494
```js

0 commit comments

Comments
 (0)