.js MIME type
JavaScripttext & code
text/javascriptJavaScript, including ES modules. RFC 9239 made text/javascript the one standard type.
| MIME type | text/javascript |
|---|---|
| Extensions | .js, .mjs, .cjs |
| Also seen as | application/javascript, application/x-javascript |
| Content-Type | text/javascript; charset=utf-8 |
| Compress in transit? | Yes — enable gzip or Brotli |
Good to know
application/javascriptstill works everywhere but is obsolete; new configs should usetext/javascript.- ES modules (
<script type="module">) are blocked unless served with a JavaScript MIME type — make sure your server maps.mjstoo. - Under
nosniff, a script served astext/plainorapplication/octet-streamis blocked.
Serve .js files with the right type
The response header to send:
Content-Type: text/javascript; charset=utf-8
Most servers pick the type from the file extension. If yours sends the wrong one, map it explicitly:
nginx (inside the types block in mime.types)
text/javascript js mjs cjs;
Apache (.htaccess or server config)
AddType text/javascript .js .mjs .cjs
Express
res.set("Content-Type", "text/javascript; charset=utf-8");Python
import mimetypes
mimetypes.add_type("text/javascript", ".js")
mimetypes.add_type("text/javascript", ".mjs")
mimetypes.add_type("text/javascript", ".cjs")HTML file input
<input type="file" accept=".js,.mjs,.cjs,text/javascript">
Check it
See what a server sends for a file, and what type a local file really is by its contents:
curl -sI https://example.com/file.js | grep -i '^content-type:' file --mime-type file.js
Frequently asked questions
What is the MIME type for .js files?
text/javascript. You may also see application/javascript, application/x-javascript, but text/javascript is the one to send. The same type covers .mjs, .cjs.
What Content-Type header should a .js file be served with?
Content-Type: text/javascript; charset=utf-8. As a text format, include the charset so browsers don't guess the encoding. It compresses well, so let the server apply gzip or Brotli.
Related types
Headers that go with it: Content-Type · Content-Disposition · X-Content-Type-Options