Jake and Surma chat about a new feature proposal, Import Maps, that lets you alter how JavaScript modules are imported. Feature proposal: goo.gle/2kslHND
just realized once again how flawed the script tag is. If it would just parse its content as regular HTML, like any other Tag does, you would just write </script> and be okay
@@digioi I assumed that this code will be inlined into HEAD , thus when it executes dom is not built yet completely (maybe BODY is not even yet in the dom). My guess was that this way they could use insertAdjacentHTML which would literally splice this tag right after the executing script tag and seems cleaner.
The insertAdjacent* apis are neat! I was disappointed that none of them work with DocumentFragments though :/ I guess we would need a more generic insertAdjacentNode for that case.
Its interesting that you can override external imports via scope, not entirely sure how fun it will be tracking down why some import fails, if there was some kind of console warning or something that would let you know your current import maps may cause issues with external imports. (provided your not using some kind of bundler that generates your import maps)
Any further info on the offhand comment about not loading jQuery (or another framework) from a CDN? You seem to suggest that browsers are only caching on a domain level, and therefore won't use a copy of a CDN asset cached from another site? Can't find much info about this at all online.
What if I change the importmap script tag with JavaScript (e.g. an extension) to something else? Not sure yet, but this could create interesting cases and maybe even be a security issue? What do you think?
Good question! I imagine changing the import map would work until the first thing is imported, after which changes are ignored. I don't see a security issue.
But if we let the browser load our import modules, wouldn't we loose the feature of tree-shaking the code not used in a lib and therefore increase the total "bundle size"?
Why not allow a user to download their favorite js libs/frameworks and css frameworks before they are requested from a website? For example: Jquery/Bootstrap.css are used by so many websites why not just download it when a user has access to reliable internet connection? They can be saved in a cache like folder for later usage for offline PWA apps. Maybe it would save time and data usage? I'm not sure if this feature exists already in Chrome?
IMO, this is unnecessary complexity. This is a lot of trouble, and it seems like the only problem this solves that can't already be solved with tooling is cache invalidation.