Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
allstarschh opened this issue May 24, 2022 · 4 comments
Closed

Comments

@allstarschh
Copy link

allstarschh commented May 24, 2022

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.

@domenic
Copy link
Collaborator

domenic commented May 24, 2022

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.

@allstarschh
Copy link
Author

allstarschh commented May 24, 2022

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.

@domenic
Copy link
Collaborator

domenic commented May 24, 2022

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.

@guybedford
Copy link
Collaborator

guybedford commented May 24, 2022

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.

@domenic domenic closed this as completed Jul 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants