Skip to content

Commit c110df8

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 c110df8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/core/feature-detection.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@
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+
// The modernizr script is located outside the chunks directory.
25+
base_url = base_url.replace("chunks/", "");
2726

2827
// Inject a new one with the modernizr bundle.
2928
const script_tag = document.createElement("script");
30-
script_tag.src = script_url + "modernizr.min.js";
29+
script_tag.src = base_url + "modernizr.min.js";
3130
document.getElementsByTagName("head")[0].appendChild(script_tag);
3231
})();

0 commit comments

Comments
 (0)