DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

JavaScript Import Maps: What to Know About Stable Module Names

Import maps can keep a dependency’s import name stable as its hashed asset URL changes, so a URL update may live in one map instead of dozens of files.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

An import map lets JavaScript modules keep a stable import name while the browser loads the current file URL behind it. If dozens of files refer to the same module, you can often change its mapped URL in one place instead of updating each importer. The “40 files” in the headline is a scenario, not a measured or typical result.

What an import map changes

A module specifier is the text used in a static import statement or a dynamic import() call. Browsers need a URL to load the module. An import map supplies the browser with a lookup from a specifier to a URL. MDN describes the feature this way: “Import maps allow developers to control how the browser resolves module specifiers when importing JavaScript modules.”

As an Amazon Associate I earn from qualifying purchases.

For example, code can use the stable specifier app-library while the map points it to a versioned, hashed file such as /assets/app-library-a1b2c3.js. If a build produces a new filename, update the map target; importing code can continue using app-library.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How one URL change can replace many edits

Without indirection, importers may contain the physical filename directly. When that filename changes, every file that refers to it may need an edit. With an import map, those files refer to the stable specifier instead, and the map associates that name with the current asset URL.

  1. Choose a stable specifier for the dependency, such as app-library.

  2. Add a mapping from that specifier to the dependency’s current URL in the HTML document.

  3. Use the stable specifier in the JavaScript modules that import the dependency.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. When the asset URL changes, update the mapping to the intended new URL and deploy the matching asset.

This reduces URL maintenance; it does not publish the new asset or guarantee that a new library version is compatible with existing code. If the new version changes APIs or behavior, source changes may still be necessary.

Choose global or scoped mappings

Use a global mapping for one target

The top-level imports object maps a specifier for the document. It is the straightforward choice when all importers should resolve a name to the same module URL.

Use scopes when different parts need different versions

The scopes object lets resolution vary according to the URL path of the importing module. This can allow separate parts of an application to use different versions of the same dependency. A scope is conditional on the importer’s path; a single global mapping cannot point the same specifier to two targets in the same context. The WHATWG HTML Standard describes scoped resolution, and MDN’s JavaScript modules guide covers its use.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Put the map before dependent modules

The browser must process the import map before loading module scripts that depend on its entries. A map added after a module specifier has already been resolved cannot reliably redirect that import. Keep the map early in the document, ahead of the dependent module scripts. See MDN’s import-map reference for the element and its behavior.

Know what import maps do not cover

MDN documents HTMLScriptElement.supports("importmap") as a feature-detection method. If your audience includes browsers that do not support import maps, use a compatibility or fallback strategy appropriate to the application.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check browser support for the exact feature

Ordinary import maps have broad browser support. MDN labels them Baseline Widely Available and says they have been available across browsers since March 2023, while noting that some parts vary. Historical minimum versions listed by Web Platform DX are Chrome 89, Edge 89, Firefox 108, Safari 16.4, and Safari on iOS 16.4.

Multiple import-map elements are a separate, more limited capability, not something to infer from ordinary import-map support. Web Platform DX lists support for multiple maps in Chrome 133 and Safari 18.4, but not Firefox; it labels the feature Limited availability. Check the browser matrix for your users before relying on multiple map elements. A single map avoids depending on that newer capability.

When this approach is useful

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.