text/*
text/javascript
File extensions: .js, .mjs
JavaScript source — the modern canonical media type for JS files.
What is text/javascript?
text/javascript is the canonical media type recommended by the HTML Living Standard for JavaScript files. It replaces application/javascript in modern usage, though both still work in every browser.
Typical usage
External <script src> files, ES modules, service workers.
Common gotchas
ES modules require the correct MIME type. Serving a .mjs file as text/plain or application/octet-stream causes the browser to reject the module load.
HTTP header example
Response header
Content-Type: text/javascript; charset=utf-8Reference
HTML Living Standard
Frequently asked questions
What is the text/javascript MIME type?
text/javascript is the canonical media type recommended by the HTML Living Standard for JavaScript files. It replaces application/javascript in modern usage, though both still work in every browser.
What file extension does text/javascript use?
Files served as text/javascript typically use the extensions .js, .mjs. The most common is .js.
How do I set the Content-Type for text/javascript?
Send the HTTP response header Content-Type: text/javascript; charset=utf-8. External <script src> files, ES modules, service workers.
Is text/javascript an official MIME type?
Yes. text/javascript is officially registered with IANA (HTML Living Standard), so standards-conformant clients recognize it.
What are common mistakes with text/javascript?
ES modules require the correct MIME type. Serving a .mjs file as text/plain or application/octet-stream causes the browser to reject the module load.