Media type · text/javascript

text/javascript

text/javascript is the standard media type for JavaScript source files.

Key facts

Typetext/javascript
Extensions.js, .mjs
StandardRFC 9239
Text or binaryText
Legacy typeapplication/javascript

What text/javascript is

RFC 9239 makes text/javascript the preferred media type for JavaScript. It is used for classic scripts, modules and JavaScript served to browsers. application/javascript is obsolete but still accepted by browsers for compatibility.

MIME checking and modules

Module scripts (type="module") are subject to strict MIME checking: a module served as text/plain is rejected. With X-Content-Type-Options: nosniff, classic scripts are checked too. This is a security feature: it stops a server from letting an uploaded text file execute as script. If a script works when pasted inline but fails when loaded from a file, the response type is the first thing to check.

Frequently asked questions

Should I use text/javascript or application/javascript?

Use text/javascript. RFC 9239 designates it as the standard type; application/javascript is obsolete.

Why does my module script fail with a MIME type error?

The server is not sending a JavaScript media type. Modules require text/javascript or another registered JavaScript type, especially when nosniff is enabled.

New tools, straight to your inbox

One short email when we add tools worth using. No spam, unsubscribe anytime.