From 35db46c83c87e58d4bf0b8ac4a5e3e601ba9f7c1 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Mon, 19 Dec 2016 14:59:17 -0500 Subject: [PATCH] Add examples of how module maps are keyed This transposes some of the wisdom from https://github.com/whatwg/html/pull/443#issuecomment-171717702 into the spec. --- source | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/source b/source index f5f93fd5276..ffaee726c81 100644 --- a/source +++ b/source @@ -87754,7 +87754,41 @@ document.querySelector("button").addEventListener("click", bound); URL">absolute URLs to values that are either a module script, null (used to represent failed fetches), or a placeholder value "fetching". Module maps are used to ensure that imported JavaScript modules are - only fetched, parsed, and evaluated once per Document or worker.

+ only fetched, parsed, and evaluated once per Document or worker.

+ +
+

Since module maps are keyed by URL, the following code will + create four separate entries in the module map, since it results in four different + URLs:

+ +
import "https://example.com/module.js";
+import "https://example.com/module.js#map-buster";
+import "https://example.com/%6dodule.js";
+import "https://example.com/module.js?debug=true";
+ +

That is, URL queries and fragments can be varied to create distinct entries in the + module map; they are not ignored. Similarly, no canonicalization beyond that + performed by the URL parser is applied, even if the same resource would be fetched from the server. Thus, four separate fetches and four + separate module evaluations will be performed.

+ +

In contrast, the following code would only create a single entry in the module + map, since after applying the URL parser to these inputs, the resulting URL records are equal:

+ +
import "https://example.com/module2.js";
+import "https:example.com/module2.js";
+import "https://///example.com\\module2.js";
+import "https://example.com/foo/../module2.js";
+ +

So in this second example, only one fetch and one module evaluation will occur.

+ +

Note that this behavior is the same as how shared workers are keyed by their parsed constructor url.

+

To resolve a module specifier given a module script script and a string specifier, perform the following steps. It will return either an