Skip to content

Commit 89141ae

Browse files
committed
fix(core feature-detection): Fix loading of modernizr script.
In some situations loading of the modernizr.min.js script failed because the base url could be incorrect. That is fixed with a non-IE compatible method of getting the current's script URL, which is safe to use. The problem surfaced in Plone while loading the Patternslib library and in between the protect.js script was loaded. The base url was calculated for the protect.js script and the modernizr script could not be loaded.
1 parent a3b6f48 commit 89141ae

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/core/feature-detection.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
}
1919

2020
// Get the current script tag's URL.
21-
// See: https://stackoverflow.com/a/984656/1337474
22-
const scripts = document.getElementsByTagName("script");
23-
const script = scripts[scripts.length - 1];
24-
let script_url = script.src;
21+
const script_url = document.currentScript.src;
2522
// Get the base URL of the current script tag's URL.
26-
script_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/";
23+
let base_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/";
24+
base_url = base_url.replace("chunks/", "");
2725

2826
// Inject a new one with the modernizr bundle.
2927
const script_tag = document.createElement("script");
30-
script_tag.src = script_url + "modernizr.min.js";
28+
script_tag.src = base_url + "modernizr.min.js";
3129
document.getElementsByTagName("head")[0].appendChild(script_tag);
3230
})();

0 commit comments

Comments
 (0)