Skip to content

gh-92626: Correct JavaScript MIME types + extensions per RFC 9239 - #92627

Closed
mathiasbynens wants to merge 3 commits into
python:mainfrom
mathiasbynens:rfc-9239
Closed

gh-92626: Correct JavaScript MIME types + extensions per RFC 9239#92627
mathiasbynens wants to merge 3 commits into
python:mainfrom
mathiasbynens:rfc-9239

Conversation

@mathiasbynens

@mathiasbynensmathiasbynens commented May 10, 2022

Copy link
Copy Markdown

This patch updates the MIME type configuration per RFC 9239.
https://www.rfc-editor.org/rfc/rfc9239

First, the recommended MIME type is now text/javascript:

The most widely supported media type in use is text/javascript; all
others are considered historical and obsolete aliases of text/javascript.

Second, the .mjs extension is now explicitly registered:

The .mjs file extension signals that the file represents a JavaScript
module. Execution environments that rely on file extensions to
determine how to process inputs parse .mjs files using the Module
grammar of [ECMA-262].

cpython already had an entry for .mjs (great!), but it was using the obsolete
MIME type.

IANA template: https://www.iana.org/assignments/media-types/text/javascript

Issue: #92626

This patch updates the MIME type configuration per RFC 9239.
https://www.rfc-editor.org/rfc/rfc9239
First, the recommended MIME type is now `text/javascript`:
> The most widely supported media type in use is `text/javascript`; all
> others are considered historical and obsolete aliases of `text/javascript`.
Second, the `.mjs` extension is now explicitly registered:
> The `.mjs` file extension signals that the file represents a JavaScript
> module. Execution environments that rely on file extensions to
> determine how to process inputs parse `.mjs` files using the Module
> grammar of [ECMA-262].
IANA template: https://www.iana.org/assignments/media-types/text/javascript
@mathiasbynens
mathiasbynens requested a review from a team as a code ownerMay 10, 2022 14:50
@ghost

ghost commented May 10, 2022

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-bot

Copy link
Copy Markdown

Every change to Python requires a NEWS entry.

Please, add it using the blurb_it Web app or the blurb command-line tool.

@arhadthedev

Copy link
Copy Markdown
Member

RFC: 9239
Published: May 2022

6.1.Common JavaScript Media Types
6.1.1. text/javascript

🎉🎉🎉 Finally encoding-aware human-readable text is treated as such (text/*) instead of binary blobs (application/*).

text

Text-only data including any human-readable content, source code, or textual data such as comma-separated value (CSV) formatted data.

application

Any kind of binary data that doesn't fall explicitly into one of the other types; either data that will be executed or interpreted in some way or binary data that requires a specific application or category of application to use. Generic binary data (or binary data whose true type is unknown) is application/octet-stream. Other common examples include application/pdf, application/pkcs8, and application/zip.

-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types

@AA-TurnerAA-Turner added stdlib Standard Library Python modules in the Lib/ directory topic-email labels May 27, 2022
@AA-Turner

Copy link
Copy Markdown
Member

Lib/test/mime.types should maybe be updated, although it seems that file hasn't been substantively updated since 2011:

# text/javascript obsoleted by application/javascript

Also:

AddType application/javascript js
AddType application/wasm wasm
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html application/javascript application/wasm

A

@AA-Turner

Copy link
Copy Markdown
Member

@warsaw would we backport something like this? I'm unsure if it would count as a bugfix.

A

@arhadthedev

Copy link
Copy Markdown
Member

It would be great to have this PR merged since it brings stuff to the latest RFC.

@encukou

Copy link
Copy Markdown
Member

This was changed in #97934. Apologies for forgetting this PR.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewstdlibStandard Library Python modules in the Lib/ directorytopic-email

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mathiasbynens@bedevere-bot@arhadthedev@AA-Turner@encukou