devkult_
tools29converters34

.js MIME type

JavaScripttext & code

text/javascript

JavaScript, including ES modules. RFC 9239 made text/javascript the one standard type.

MIME typetext/javascript
Extensions.js, .mjs, .cjs
Also seen asapplication/javascript, application/x-javascript
Content-Typetext/javascript; charset=utf-8
Compress in transit?Yes — enable gzip or Brotli

Good to know

  • application/javascript still works everywhere but is obsolete; new configs should use text/javascript.
  • ES modules (<script type="module">) are blocked unless served with a JavaScript MIME type — make sure your server maps .mjs too.
  • Under nosniff, a script served as text/plain or application/octet-stream is 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