From 4b4a1b63d740c8fefe73b81ea99f60496035d257 Mon Sep 17 00:00:00 2001 From: Pranjali Date: Sun, 12 Oct 2025 01:40:37 +0530 Subject: [PATCH 1/6] Improved Documentation --- src/content/guides/web-workers.mdx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 19caf47b5d3e..591d53695ede 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -62,4 +62,21 @@ import { Worker } from 'worker_threads'; new Worker(new URL('./worker.js', import.meta.url)); ``` -Note that this is only available in ESM. `Worker` in CommonJS syntax is not supported by either webpack or Node.js. +--- + +## Advanced: Cross-Domain and Dynamic Web Workers + +In some setups you might need your worker script to be hosted on a different origin +(for example, using a CDN or micro-frontend). +Webpack supports this, but you must make the worker aware of the correct public path. + +### Setting a dynamic public path + +Inside the worker, explicitly set the same public path used by the main bundle: + +```js +// worker.js +/* global __webpack_public_path__, __webpack_require__ */ + +// Ensure the worker knows where to load chunks from +__webpack_public_path__ = __webpack_require__.p = self.location.origin + '/assets/'; From 94688f6805a823f443abb0cd842ae7a42a8f8d4a Mon Sep 17 00:00:00 2001 From: Pranjali Srivastava Date: Sun, 12 Oct 2025 01:46:49 +0530 Subject: [PATCH 2/6] Update web-workers.mdx --- src/content/guides/web-workers.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 591d53695ede..03c6be892565 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -63,6 +63,7 @@ new Worker(new URL('./worker.js', import.meta.url)); ``` --- +Note that this is only available in ESM. `Worker` in CommonJS syntax is not supported by either webpack or Node.js. ## Advanced: Cross-Domain and Dynamic Web Workers From 7d4e781edf7ca9452c532363e2fbf89161297371 Mon Sep 17 00:00:00 2001 From: Pranjali Srivastava Date: Mon, 13 Oct 2025 14:00:45 +0530 Subject: [PATCH 3/6] Update web-workers.mdx --- src/content/guides/web-workers.mdx | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 03c6be892565..182737bc77d2 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -67,17 +67,21 @@ Note that this is only available in ESM. `Worker` in CommonJS syntax is not supp ## Advanced: Cross-Domain and Dynamic Web Workers -In some setups you might need your worker script to be hosted on a different origin -(for example, using a CDN or micro-frontend). -Webpack supports this, but you must make the worker aware of the correct public path. +In some setups, you may need your worker script to be hosted on a different origin +(for example, on a CDN or within a micro-frontend). +Webpack supports this, but the worker must know the correct **public path** at runtime. -### Setting a dynamic public path +### Setting a dynamic public path safely -Inside the worker, explicitly set the same public path used by the main bundle: +The recommended approach is to define `__webpack_public_path__` at the beginning of your worker entry file, before any imports. +This lets webpack resolve chunk URLs correctly without editing generated code: ```js // worker.js -/* global __webpack_public_path__, __webpack_require__ */ -// Ensure the worker knows where to load chunks from -__webpack_public_path__ = __webpack_require__.p = self.location.origin + '/assets/'; +// Define the public path dynamically before loading other modules +/* eslint-disable camelcase */ +__webpack_public_path__ = self.location.origin + '/assets/'; + +// Then import or execute the rest of your worker logic +importScripts('deep-thought.js'); From 2583c9cd29497d5bd8eac9f733caf22528852259 Mon Sep 17 00:00:00 2001 From: Pranjali Srivastava Date: Tue, 14 Oct 2025 00:39:58 +0530 Subject: [PATCH 4/6] Removed prefix "advanced" --- src/content/guides/web-workers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 182737bc77d2..660fe6789f80 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -65,7 +65,7 @@ new Worker(new URL('./worker.js', import.meta.url)); --- Note that this is only available in ESM. `Worker` in CommonJS syntax is not supported by either webpack or Node.js. -## Advanced: Cross-Domain and Dynamic Web Workers +Cross-Domain and Dynamic Web Workers In some setups, you may need your worker script to be hosted on a different origin (for example, on a CDN or within a micro-frontend). From 97b160b9e8a118b0e3edc0142a5f1c1ac928d823 Mon Sep 17 00:00:00 2001 From: Pranjali Srivastava Date: Wed, 15 Oct 2025 01:00:59 +0530 Subject: [PATCH 5/6] Made cross-domain as title --- src/content/guides/web-workers.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 660fe6789f80..00e94de6d1cb 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -65,7 +65,7 @@ new Worker(new URL('./worker.js', import.meta.url)); --- Note that this is only available in ESM. `Worker` in CommonJS syntax is not supported by either webpack or Node.js. -Cross-Domain and Dynamic Web Workers +### Cross-Domain and Dynamic Web Workers In some setups, you may need your worker script to be hosted on a different origin (for example, on a CDN or within a micro-frontend). From dc8fb1f4699f0c5c84b28f3af52a90d44cf1f3ae Mon Sep 17 00:00:00 2001 From: Pranjali Srivastava Date: Tue, 4 Nov 2025 19:16:41 +0530 Subject: [PATCH 6/6] Revise web workers guide to remove dynamic path section Removed unnecessary section on dynamic public path in web workers guide. --- src/content/guides/web-workers.mdx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/content/guides/web-workers.mdx b/src/content/guides/web-workers.mdx index 00e94de6d1cb..48d04bc53aaa 100644 --- a/src/content/guides/web-workers.mdx +++ b/src/content/guides/web-workers.mdx @@ -68,10 +68,6 @@ Note that this is only available in ESM. `Worker` in CommonJS syntax is not supp ### Cross-Domain and Dynamic Web Workers In some setups, you may need your worker script to be hosted on a different origin -(for example, on a CDN or within a micro-frontend). -Webpack supports this, but the worker must know the correct **public path** at runtime. - -### Setting a dynamic public path safely The recommended approach is to define `__webpack_public_path__` at the beginning of your worker entry file, before any imports. This lets webpack resolve chunk URLs correctly without editing generated code: