Skip to content

Commit 4b4a1b6

Browse files
committed
Improved Documentation
1 parent fd94d2a commit 4b4a1b6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/content/guides/web-workers.mdx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,21 @@ import { Worker } from 'worker_threads';
6262
new Worker(new URL('./worker.js', import.meta.url));
6363
```
6464
65-
Note that this is only available in ESM. `Worker` in CommonJS syntax is not supported by either webpack or Node.js.
65+
---
66+
67+
## Advanced: Cross-Domain and Dynamic Web Workers
68+
69+
In some setups you might need your worker script to be hosted on a different origin
70+
(for example, using a CDN or micro-frontend).
71+
Webpack supports this, but you must make the worker aware of the correct public path.
72+
73+
### Setting a dynamic public path
74+
75+
Inside the worker, explicitly set the same public path used by the main bundle:
76+
77+
```js
78+
// worker.js
79+
/* global __webpack_public_path__, __webpack_require__ */
80+
81+
// Ensure the worker knows where to load chunks from
82+
__webpack_public_path__ = __webpack_require__.p = self.location.origin + '/assets/';

0 commit comments

Comments
 (0)