Skip to content

Conversation

@hamishwillee
Copy link
Collaborator

As discussed in #42306 (comment) the description of import assertions does not provide an easy way to link to particular parts of the concepts, such as a definition of CSS Modules imported using with { type: "css"}.

This restructures the existing material to provide some headings. Should allow clean linking to the doc, easier parsing for readers, and maintenance if we later add other module types.

@Josh-Cena Obviously "for discussion and iteration". It is almost all a restructure, with only a tiny amount of new content, which I will highlight.

Related docs work being done in #42255

@hamishwillee hamishwillee requested a review from a team as a code owner December 9, 2025 05:26
@github-actions github-actions bot added Content:JS JavaScript docs size/m [PR only] 51-500 LoC changed labels Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Preview URLs

External URLs (2)

URL: /en-US/docs/Web/JavaScript/Reference/Statements/import/with
Title: Import attributes

(comment last updated: 2026-01-06 00:36:06)

@sideshowbarker sideshowbarker removed the request for review from a team December 9, 2025 16:21
```

Modules are identified and parsed only according to their served [MIME type](/en-US/docs/Web/HTTP/Guides/MIME_types) — the file extension in the URL cannot be used to identify a file's type. In this case, the MIME type is `application/json`, which tells the browser that the file is JSON and must be parsed as JSON. If, for some reason (e.g., the server is hijacked or bogus), the MIME type in the server response is set to `text/javascript` (for JavaScript source), then the file would be parsed and executed as code. If the "JSON" file actually contains malicious code, the `import` declaration would unintentionally execute external code, posing a serious security threat.
Modules are identified and parsed only according to their served [media type (MIME type)](/en-US/docs/Web/HTTP/Guides/MIME_types) — the file extension in the URL cannot be used to identify a file's type. In this case, the MIME type is `application/json`, which tells the browser that the file is JSON and must be parsed as JSON. If, for some reason (e.g., the server is hijacked or bogus), the MIME type in the server response is set to `text/javascript` (for JavaScript source), then the file would be parsed and executed as code. If the "JSON" file actually contains malicious code, the `import` declaration would unintentionally execute external code, posing a serious security threat.
Copy link
Member

Choose a reason for hiding this comment

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

For my education, because Brian has made the same comment: why is "MIME type" not in fashion anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The IANA decided they didn't like MIME, AIUI because the "E" is for email - and media types are used much more widely. They own the list of media types, and decided that henceforth we'll use this term.

FWIW I don't like it because media type is a much more general term that could mean anything, not just the registered types formerly known as MIME. Hence the clarification on first use.

Comment on lines 66 to 67
Import attributes fix this problem by allowing the author to explicitly specify how a module should be validated.
When using import attributes the code above would be written as shown below, and would fail if the file was served with any media type other than `application/json`:
Copy link
Member

Choose a reason for hiding this comment

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

This flows a bit weirder than before IMO. The intended logic was: browsers always have strict MIME validation, and the import above failed validation > MIME validation is done via the type key (implying that other keys can exist for other purposes) > JSON modules correspond to type: "json" > then the example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. I've attempted to more closely match your intent in 3300ed0

@hamishwillee hamishwillee force-pushed the import_assertions_restructure_description branch 2 times, most recently from d5ca233 to 22d5fd8 Compare December 15, 2025 22:50
@hamishwillee
Copy link
Collaborator Author

@Josh-Cena Did the updates address your concerns?

@Josh-Cena
Copy link
Member

Sorry, was extremely busy. I'll look later this week.

@hamishwillee hamishwillee force-pushed the import_assertions_restructure_description branch from e21aa17 to d3f2c73 Compare January 6, 2026 00:34
Copy link
Member

@pepelsbey pepelsbey left a comment

Choose a reason for hiding this comment

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

Thank you, everyone! Looks good to me from the editorial perspective. I’m going to merge it for the 147 release. Feel free to make additional changes in a separate PR.

@pepelsbey pepelsbey merged commit be011c2 into mdn:main Jan 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants