JavaScript import maps can be injected dynamically today using a classic blocking script that creates a `<script type="importmap">` element via DOM methods and inserts it after itself using `document.currentScript.after()`. This technique works back to Chrome 89, Safari 16.4+, and Firefox 108+, and is already used by JSPM v4. The post provides minimal code examples including URL rebasing for relative paths and error handling. While this workaround reduces the urgency for native external import map support (`<script type="importmap" src="...">`) it doesn't eliminate the need — HTML remains the only way to include import maps, creating architectural debt and limitations like import maps not working in worker scripts. The author advocates for deeper platform-wide integration of specifiers and import maps, and hints at an upcoming tool for build-free dependency management built on top of JSPM Generator.

7m read timeFrom lea.verou.me
Post cover image
Table of contents
How does it work?Do we still need external import maps?Enjoyed this post?Reactions

Sort: