WICG/import-maps

Speculatively parsing with import map if there's a dynmic import before,

Closed this issue · 4 comments

Per https://github.com/WICG/import-maps#interaction-with-speculative-parsingfetching,
I'd like to ask whether we should preload the import map or not.

If there's a dynamic import call before the import map tag,

<script> import("foo.js"); </script> <script type="importmap">...</script> <script type="module" src="bar.mjs"></script>

According to the spec, the dynamic import call will set acquiring importmaps to false, so the following import map shouldn't be accepted, and if bar.mjs uses the specifier from the import map, that should also fail.

It looks fine if the parser doesn't preload the importmap script tag and module script tag, but if it does preloading, the fetching for bar.mjs seems wasted.

It's really up to the implementing browser? Like all speculative parsing, that's an optimization you can choose to perform, which may be wasted or may be useful.

Although in the case you list, I'm not sure what you mean by "preload the import map", since it is inline.

Although in the case you list, I'm not sure what you mean by "preload the import map", since it is inline.

I am trying to preload the inline import map script tag as well, as the speculative parser will try to preload the module script tag.
If the parser didn't preload the import map tag, then the module script won't be able to resolve the specifier from the import map.

However, if the parser preloads the import map tag, but it won't know the dymanic import call from the javascript, and 'accepts' the import map tag instead.

I'd like to point out that with import map tag, preloading and non-preloading module scripts (for speculative parsing) could possibly have different bahaviors.

Yep, that's what that section is about! Like <base> or <script>, <script type=importmap> can cause preloading and non-preloading URL resolution to differ.

It probably still makes sense to incorporate import maps when available into the preloading, assuming they will apply, unless there is an obvious statically detectable violation like a module script before an import map tag.