text/javascript MIME Type — JavaScript Content-Type & ES Modules
JavaScript source code. The official MIME type for JavaScript since RFC 9239 (2022), replacing the deprecated application/javascript. Used for <script src> files, dynamic script injection, and module imports. Browsers enforce this type for ES modules.
Used For
- Browser JavaScript files
- Node.js ES modules (.mjs)
- Service workers
- Web workers
HTTP Header Example
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8
Cache-Control: public, max-age=31536000Code Examples
// Express — serve JS files
app.use(express.static('public')) // text/javascript assigned automatically
// nginx
types {
text/javascript js mjs;
}
// ES module import requires text/javascript (application/javascript rejected in some browsers)
// <script type="module" src="/app.mjs"></script>
// The server MUST return Content-Type: text/javascript for modulesRelated MIME Types
Frequently Asked Questions
What is the text/javascript MIME type?
JavaScript source code. The official MIME type for JavaScript since RFC 9239 (2022), replacing the deprecated application/javascript. Used for <script src> files, dynamic script injection, and module imports. Browsers enforce this type for ES modules.
When should I set Content-Type: text/javascript?
Set Content-Type: text/javascript on HTTP responses that contain JavaScript data. Browser JavaScript files.
What file extensions use text/javascript?
Files with text/javascript content typically use these extensions: .js, .mjs, .cjs.
What happens if I serve this with the wrong Content-Type?
Browsers use the Content-Type header to decide how to handle the response. Serving text/javascript content with an incorrect MIME type can cause browsers to display it incorrectly, refuse to execute it (scripts), or prompt an unintended download. Modern browsers respect X-Content-Type-Options: nosniff and will not attempt to auto-detect the type.
