text/javascript
RFC 9239 (2022) made text/javascript the one type for JavaScript and marked application/javascript and the other names obsolete. Browsers still accept the old names, but module scripts refuse anything that is not a JavaScript type.
Open in cURL Builder A request with this type is filled in.
Header
Content-Type: text/javascript; charset=utf-8At a glance
- Extensions
- .js, .mjs
- Kind
- Text
- Parameters
charset; sendutf-8. Module scripts are always read as UTF-8.- In a browser
- Opened directly, shows the source. Loaded with
<script>, runs it.
With curl
curl -I https://example.com/app.js
With fetch
const res = await fetch('https://example.com/app.js');
console.log(res.headers.get('Content-Type'));Common mistakes
Modules need a JavaScript type
A
<script type="module">or animportis refused when the response has another type, and the console says the server answered with the wrong MIME type. Fix the server's mapping for.jsand.mjs.nosniff blocks mislabeled scripts
With
X-Content-Type-Options: nosniff, a classic script served astext/plainortext/htmlis blocked too. That is the protection you want, so fix the type rather than drop the header.application/javascriptstill worksServers that send it are not broken: browsers accept it. Switch to
text/javascriptthe next time you touch the config.