From 3e50a51b7970a57650e699a89c9aab23073d3fd8 Mon Sep 17 00:00:00 2001 From: Yoav Weiss Date: Tue, 21 Jan 2025 14:36:55 +0100 Subject: [PATCH] Cover multiple import maps --- .../html/element/script/type/importmap/index.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/files/en-us/web/html/element/script/type/importmap/index.md b/files/en-us/web/html/element/script/type/importmap/index.md index 9e6e536b92641fa..5a43b47408539be 100644 --- a/files/en-us/web/html/element/script/type/importmap/index.md +++ b/files/en-us/web/html/element/script/type/importmap/index.md @@ -28,8 +28,6 @@ For more information, see the [Importing modules using import maps](/en-US/docs/ The `src`, `async`, `nomodule`, `defer`, `crossorigin`, `integrity`, and `referrerpolicy` attributes must not be specified. -Only the first import map in the document with an inline definition is processed; any additional import maps and external import maps are ignored. - ### Exceptions - `TypeError` @@ -37,9 +35,6 @@ Only the first import map in the document with an inline definition is processed Browsers generate console warnings for other cases where the import map JSON does not conform to the [import map](#import_map_json_representation) schema. -An [`error` event](/en-US/docs/Web/API/HTMLElement/error_event) is fired at script elements with `type="importmap"` that are not processed. -This might occur, for example, if module loading has already started when an import map is processed, or if multiple import maps are defined in the page. - ## Description When importing a [JavaScript module](/en-US/docs/Web/JavaScript/Guide/Modules), both the [`import` statement](/en-US/docs/Web/JavaScript/Reference/Statements/import) and [`import()` operator](/en-US/docs/Web/JavaScript/Reference/Operators/import) have a "module specifier" that indicates the module to be imported. @@ -213,6 +208,18 @@ The import map must be a valid JSON object that can define any of the optional k Note that the scope does not change how an address is resolved; relative addresses are always resolved to the import map base URL. +## Merging multiple import maps + + + +Internally, browsers maintain a single global import map representation. + +When an import map is registered, its contents are merged into the global import map. + +Module specifiers in the registered map that were already resolved before are dropped. Future resolution of these specifiers will provide the same results as their previous resolution. + +Module specifiers in the registered map that were already mapped to URLs in the global map are similarly dropped and their previous mapping prevails. + ## Specifications {{Specifications}}