Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Dynamic import-map tag insertion and prefetching #218

Closed
moztcampbell opened this issue May 22, 2020 · 5 comments
Closed

Dynamic import-map tag insertion and prefetching #218

moztcampbell opened this issue May 22, 2020 · 5 comments

Comments

@moztcampbell
Copy link

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:

<script src="maybe_dynamic_importmap.js"></script>
<script src="module_root.mjs" type="module"></script>

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.

@domenic
Copy link
Collaborator

domenic commented May 22, 2020

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.

@moztcampbell
Copy link
Author

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.

@domenic
Copy link
Collaborator

domenic commented May 22, 2020

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.

@moztcampbell
Copy link
Author

Got it. Thanks.

@annevk
Copy link

annevk commented May 26, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants