-
-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add script type="module" support #84
Comments
You should be able to do this using the loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
success: function() {},
error: function(pathsNotFound) {},
before: function(path, scriptEl) {
/* called for each script node before being embedded */
if (path === '/path/to/foo.js') scriptEl.type = "module";
}
}); Let me know if that helps. |
I hadn't considered that hook, thanks! Would still be nice to have this embedded into the loader, however. I'm trying to keep the amount of code written to the page as small as possible, and the above is relatively verbose. |
You can compress that down to something like: before: function(p, l) { p == ‘/path’ && l.type= “module” } If you are only targeting modern browsers you can make it even smaller: before: (p, l) => p == ‘/path’ && l.type= “module” In order to make that even smaller, it would probably require more code in loadjs. If you found a way somehow to make it smaller it’s probably not going to be super benefitial. |
Yep, makes sense. I guess I'm just thinking if you have a lot of scripts to load, and each needs to add the
|
https://developers.google.com/web/fundamentals/primers/modules
Accept
args.module = true
for a particular script to addtype="module"
. It would be up to consumers to do a feature detect:'noModule' in document.createElement('script')
...to decide which script to request in loadJs, but using the same identifier for both that and a traditional script.
The text was updated successfully, but these errors were encountered: