What is the MIME type of .js files?
The MIME type (media type) for JavaScript files with the .js extension is text/javascript. You may also see application/javascript. The same type is used for .mjs. RFC 9239 (2022) made text/javascript the official type; application/javascript is still accepted everywhere. ES modules loaded with <script type="module"> must be served with a JavaScript MIME type or the browser blocks them.
Content-Type header
Content-Type: text/javascript; charset=utf-8
Text-based types should include a charset so the browser decodes characters correctly.
Server configuration
| Server | Configuration |
|---|---|
Nginx (mime.types or types {}) | text/javascript js; |
Apache (.htaccess) | AddType text/javascript .js |
IIS (web.config) | <mimeMap fileExtension=".js" mimeType="text/javascript" /> |
| Node.js / Express | res.type('js') or res.setHeader('Content-Type', 'text/javascript; charset=utf-8') |
| Amazon S3 | Set Content-Type: text/javascript on the object (metadata), or pass --content-type text/javascript to aws s3 cp |
Should .js files be compressed?
Yes. JavaScript is text, so enabling gzip or Brotli for text/javascript typically saves 50–80 % of the transfer size. Make sure your server’s compression list includes this type — check with the website compression test.
Why the MIME type matters
Browsers decide what to do with a response — render, run, play or download — from the Content-Type header, not the file extension. With X-Content-Type-Options: nosniff, a wrong type causes stylesheets and scripts to be blocked outright. For uploads, never trust the type sent by the client; check the file’s content (its magic bytes) on the server.
Frequently asked questions
What is the MIME type for .js?
text/javascript. Alternatives seen in the wild: application/javascript.How do I set the Content-Type for .js in Nginx?
text/javascript js; is listed in the types block (usually in /etc/nginx/mime.types) and reload Nginx.