Request: allow override to retrieve auto-imported script element
See original GitHub issueDescription of Proposed Feature
Auto-import is a great feature we rely on to load our app inlined. However, in some cases, the retrieval of the current running script will not be correct, as the last script might not always be the running script. (https://github.com/systemjs/systemjs/blob/master/src/features/script-load.js#L40)
systemJSPrototype.register = function (deps, declare) {
if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length - 1]; // not always the running script
var url = lastScript && lastScript.src;
if (url) {
lastAutoImportUrl = url;
This proposal would extract the retrieval of the current script into a separate, overridable, hook:
systemJSPrototype.getCurrentScript = function () {
var scripts = document.getElementsByTagName('script');
return scripts[scripts.length - 1];
};
systemJSPrototype.register = function (deps, declare) {
if (hasDocument && document.readyState === 'loading' && typeof deps !== 'string') {
var lastScript = systemJSPrototype.getCurrentScript();
var url = lastScript && lastScript.src;
if (url) {
lastAutoImportUrl = url;
In what way would you use it?
In the end state, when we drop support for IE 11 in our app, we would use document.currentScript
in order to always have the correct current script:
systemJSPrototype.getCurrentScript = function () {
return document.currentScript;
};
In the meantime, we would use the hook to return the correct script element dynamically. It would also allow us to prevent the import of incorrectly matched last scripts when dynamic loads have been used.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (7 by maintainers)
Top Results From Across the Web
javascript - How can I access built-in methods of an Object that ...
I'm looking for a way to somehow restore the reference to the method in my userscript. The problem is that the website can...
Read more >The Script element - HTML: HyperText Markup Language
Provides a hint of the relative priority to use when fetching an external script. Allowed values: high. Signals a high-priority fetch relative ...
Read more >Documentation - TypeScript 4.0
Labeled Tuple Elements. Improving the experience around tuple types and parameter lists is important because it allows us to get strongly typed validation ......
Read more >Announcing TypeScript 4.0 - Microsoft Developer Blogs
Today we are thrilled to announce the availability of TypeScript 4.0! This version of the language represents our next generation of ...
Read more >sbt Reference Manual — Plugins
Managed dependencies declared by the project/ project are retrieved and are ... We call these triggered plugins, and they are created by overriding...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was finally able to reproduce it! 😃 https://plnkr.co/edit/dMPuci6LJh0smbyu
Some remarks about the repro:
document.write
inindex.html
is used in order to fake a sync third party library, but I wanted to use a file in the same project for it (animals/chicken.js
)flash.siwalik.in
(a https variant of Slowwly)triton.js
). These dependencies are retrieved with a url that is constructed using the wrong base url. That wrong base url is coming fromdocument.getElementsByTagName('scripts')
which retrieves the last script instead of the current script.Let me know if can help more!
@tmsns this fix was released in 6.6.0 and 6.6.1, just let me know if you hit any further issues here or need to reopen.