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

Support link modulepreload for import assertions #7388

Open
uasan opened this issue Dec 4, 2021 · 6 comments
Open

Support link modulepreload for import assertions #7388

uasan opened this issue Dec 4, 2021 · 6 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: link

Comments

@uasan
Copy link

uasan commented Dec 4, 2021

Hello.
The current implementation in Chrome does not support the <link rel=modulepreload> for import assertions
https://bugs.chromium.org/p/chromium/issues/detail?id=1274871

The specification says that you can specify the as attribute

Let destination be the current state of the as attribute (a destination), or "script" if it is in no state.
https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload

But as not support and has not valid as value for type json module.

Perhaps it makes sense to add support for the type attribute?

for ESM module
<link rel="modulepreload" href="app.mjs">

for assert type css
<link rel="modulepreload" href="style.css" type="text/css">

for assert type json
<link rel="modulepreload" href="data.json" type="application/json">

Thanks.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: link labels Dec 6, 2021
@annevk
Copy link
Member

annevk commented Dec 6, 2021

cc @whatwg/modules

@dandclark
Copy link
Contributor

I agree that this is needed, thanks for raising the issue.

Instead of using MIME type for the values, I think we could just use the same shorter strings as import assertions:

<link rel="modulepreload" href="app.mjs">
<link rel="modulepreload" href="style.css" type="css">
<link rel="modulepreload" href="data.json" type="json">

For the attribute name, type is nice in that it matches the name for import assertions, but I wonder if it should be more specific to prevent confusion with <link> use cases other than modulepreload. Maybe a name like:

<link rel="modulepreload" href="style.css" moduletype="css">`

or even

<link rel="modulepreload" href="style.css" modulepreloadtype="css">

An alternative idea is to add new rel values for each type:

<link rel="modulepreload" href="app.mjs">
<link rel="cssmodulepreload" href="style.css">
<link rel="jsonmodulepreload" href="data.json">

@bmeck
Copy link

bmeck commented Dec 6, 2021

I think having some way to do this is good, but it seems precarious given that arbitrary key/values are allowed for assertions to only cater to a single one as a special case.

@domenic
Copy link
Member

domenic commented Dec 13, 2021

I think @dandclark is on the right track. The main thing to consider is how well such ideas fit with possible future extensions.

For example, as a strawperson, you could imagine something like assert="... JSON string ..." and then the syntax would be something like

<link rel="modulepreload" href="style.css" assert='{ type: "css" }'>

<script type="module" assert='{ type: "css" }'>
.class { prop: value; }
</script>

This unfortunately has the usual quote-related problems of putting JSON in attributes, so it's mostly just a strawperson. But it's worth thinking about.

@uasan
Copy link
Author

uasan commented Dec 21, 2021

I, as a full stack developer, love when knowledge can be reused.
Therefore, I like the option most of all to use the same MIME types for clients and backend.

@domenic, Tell me the type = module is it so historically, because ESM appeared later?

<script type="module" >

In a perfect world, was it supposed to be like this type = application/javascript?

<script type="application/javascript" >

@domenic
Copy link
Member

domenic commented Dec 21, 2021

No, type=module is intentional. Application/JavaScript is not correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: link
Development

No branches or pull requests

5 participants