Skip to content

Add text imports#11933

Open
eemeli wants to merge 4 commits intowhatwg:mainfrom
eemeli:import-text
Open

Add text imports#11933
eemeli wants to merge 4 commits intowhatwg:mainfrom
eemeli:import-text

Conversation

@eemeli
Copy link
Member

@eemeli eemeli commented Nov 20, 2025

This is the HTML counterpart for the newly-introduced TC39 Import Text Stage 2 proposal; this has been previously discussed here in #9444, and is closely related (but not blocking on) PR #11657, which correspondingly adds byte imports.

The type: 'text' import attribute is introduced here without any MIME type requirement, and without any validity or well-formedness checks on the returned string value. @sffc has raised some concerns about additional validation steps being desirable for text content, which would be appropriate for consideration in this spec, rather than the JS spec.

The implementer support noted below is based on feedback from delegates at the 2025 November TC39 meeting.


/infrastructure.html ( diff )
/links.html ( diff )
/references.html ( diff )
/webappapis.html ( diff )

Adds support for the `{ type: 'text' }` import attribute,
which enables importing text content as a JavaScript string.
@annevk
Copy link
Member

annevk commented Nov 20, 2025

cc @nicolo-ribaudo @bakkot

@bakkot
Copy link
Contributor

bakkot commented Nov 22, 2025

Looks good. I do wonder whether there ought to be a required MIME type, especially given that the other types all have one. If type: "bytes" had a similar requirement (which IMO would be much more annoying), that would allay the concerns in this issue.

Alternatively there could be a requirement not to have certain MIME types, e.g. to disallow importing JavaScript as text.

I think I am personally inclined not to impose such requirements, but I could see the argument either way.

@zcorpan
Copy link
Member

zcorpan commented Nov 25, 2025

Would this make available the same content that is already available via fetch()? Is it possible to use CSP (connect-src ?) to restrict these imports?

@bakkot
Copy link
Contributor

bakkot commented Nov 25, 2025

Good question. Looks like type: "json" imports are governed by connect-src, so I assume these should be as well. This will require filing a PR against CSP updating the "Get the effective directive for request" algorithm to list requests with destination "text" as having effective directive connect-src. (Not strictly necessary because connect-src is the fallback, but it would be weird to leave it out given that "json" imports are listed explicitly.)

For clarity it might be good to rename the destination to "text-import" or something, incidentally.

Anyway, yes, this ends up letting you get the exact same content as fetch.

@nicolo-ribaudo
Copy link
Collaborator

Do we actually want a text destination? We added one for json because it's a specific format, but in most cases a text import will then be parsed by something else. fetch uses an empty destination because, similarly, we don't actually know how its result is going to be used.

@bakkot
Copy link
Contributor

bakkot commented Nov 25, 2025

json doesn't seem any more specific than text to me, really. It's just data either way.

@annevk
Copy link
Member

annevk commented Nov 25, 2025

It's specific in that we can ask the server for JSON with Accept: application/json (and we do).

Given that the destination is exposed these days through Sec-Fetch-Dest as well it would probably be useful to have a dedicated value here as well. text seems fine to me.

@bakkot
Copy link
Contributor

bakkot commented Nov 25, 2025

Oh, nice, I didn't realize that it got exposed there and wasn't just editorial. In that case I agree text is fine, as long as we don't imagine later introducing a new kind of "text" destination where the distinction is important.

@eemeli
Copy link
Member Author

eemeli commented Dec 17, 2025

I've now added PRs for the changes in the Fetch and CSP specs, and for WPT tests.

@eemeli
Copy link
Member Author

eemeli commented Mar 11, 2026

The TC39 / ECMA-262 part of this proposal has now advanced to Stage 3.

@smaug---- smaug---- added the agenda+ To be discussed at a triage meeting label Mar 12, 2026
Copy link
Collaborator

@noamr noamr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be rebased, and properly support modulepreload like CSS/JSON.

@eemeli eemeli requested a review from noamr March 12, 2026 17:58
@noamr
Copy link
Collaborator

noamr commented Mar 13, 2026

Do the tests cover module preload? The spec text seemed good AFAICT!

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 agenda+ To be discussed at a triage meeting needs implementation bugs topic: script

Development

Successfully merging this pull request may close these issues.

7 participants