Closed moztcampbell closed 4 years ago
The answer is no. Once <script src="module_root.mjs" type="module"></script>
executes, the import map is locked, and nothing can be dynamically added. So there is no delay waiting to see what maybe_dynamic_importmap.js
does.
One would still need to fetch/parse/execute the top-level of maybe_dynamic_importmap.js
to determine that the import map is locked, wouldn't they?
I'm trying to consider the case of prefetching and parsing while the DOM is still being constructed.
Sure, but you can't execute <script src="module_root.mjs" type="module"></script>
or fetch its dependencies before maybe_dynamic_importmap.js
is executed anyway, per the HTML Standard.
Got it. Thanks.
The HTML Standard also does not define <script>
can be speculatively parsed and fetched yet everyone does it (in subtly different ways). We could try to forbid that practice for module scripts, but it seems such a decision would benefit from a wider discussion.
Will the ability to insert import-map tags dynamically from out-of-line scripts harm a browser's ability to prefetch and compile module graphs?
Example:
Without import-maps, a browser is able to look at this page and reasonably expect to begin to fetch the module-graph and things it imports transitively. With this proposal, that prefetching would either have to be avoided, or we would need to refetch and recompile the module graph. The proposal seems to blame the developer in this case which suggests the browser should reasonable pre-fetch and then re-fetch if maps are used.
Pages that do not use an import-map may be inclined to put an empty
<script type="importmap"></script>
tag to reassure the browser that URI rewriting will not happen.Only allowing re-writes for non-URL import identifiers would avoid this all, but that was ruled out elsewhere in the proposal.