The JavaScript MIME Type
When sending JavaScript content, you should use text/javascript
as per RFC 9239.
Aliases
application/javascript
, application/x-javascript
, text/javascript1.0
, text/javascript1.1
, text/javascript1.2
, text/javascript1.3
, text/javascript1.4
, text/javascript1.5
, text/jscript
, and text/livescript
are deprecated aliases for it. If you are writing a tool which consumes JavaScript (e.g. an HTTP client) then you should consider supporting them for backwards compatibility.
History
The text/javascript
MIME type was used by convention until RFC 4329 attempted to replace it with application/javascript
.
This was just a change so that the text/*
and application/*
MIME type groups had a consistent meaning where possible. (text/*
MIME types are intended for human readable content, JavaScript is not designed to directly convey meaning to humans).
The industry largely ignored the specification so the current specification abandoned the attempt.
X- prefixes
Some of the MIME types mentioned here use an x-
prefix. This was used to indicate experimental MIME types that had not been standardised. As per RFC 6648, this convention is deprecated.
HTML
While this question is about HTTP, it is worth mentioning the related type
attribute in HTML.
When loading a traditional script, I recommend you omit the type
attribute entirely. It has no effect but provides the opportunity to make a typo causing the browser to treat it as pointing to an unrecognised script type and ignore it. If you do provide it, then use text/javascript
as some deprecated MIME types will not be recognised.
When loading a JavaScript module, use type="module"
(note that this value is not a MIME type!).
script
tag'stype
attribute when thenosniff
directive is specified. developer.mozilla.org/en-US/docs/Web/HTTP/Headers/…