diff --git a/web_src/js/publicpath.js b/web_src/js/publicpath.js
index 892bb459aa..38865aa666 100644
--- a/web_src/js/publicpath.js
+++ b/web_src/js/publicpath.js
@@ -1,5 +1,10 @@
-// This sets up webpack's chunk loading to load resources from the 'public'
-// directory. This file must be imported before any lazy-loading is being attempted.
+// This sets up the URL prefix used in webpack's chunk loading.
+// This file must be imported before any lazy-loading is being attempted.
+const {StaticUrlPrefix} = window.config;
 
-const url = new URL(document.currentScript.src);
-__webpack_public_path__ = url.pathname.replace(/\/[^/]*?\/[^/]*?$/, '/');
+if (StaticUrlPrefix) {
+  __webpack_public_path__ = StaticUrlPrefix.endsWith('/') ? StaticUrlPrefix : `${StaticUrlPrefix}/`;
+} else {
+  const url = new URL(document.currentScript.src);
+  __webpack_public_path__ = url.pathname.replace(/\/[^/]*?\/[^/]*?$/, '/');
+}