text/javascript
The MIME type for JavaScript source files used to add interactivity to web pages.
What Is This?
The text/javascript MIME type indicates that the content is a JavaScript source file. While text/javascript is the historical standard, application/javascript and application/ecmascript are also widely recognized. Modern browsers treat all these types the same way — they parse and execute the script.
Common Uses
Common Use
External JavaScript files loaded via <script> tags
Common Use
JavaScript module files
Common Use
Server-side JavaScript responses
Common Use
CDN-hosted library files
Examples
Serve files with the text/javascript MIME type:
# Nginx
location ~ \.js$ {
add_header Content-Type "text/javascript";
}
# Apache
AddType text/javascript .jsUse this MIME type in HTML or HTTP:
Content-Type: text/javascript <!-- HTML reference --> <link rel="preload" href="file.js" as="fetch" crossorigin>
Related Entries
More from this reference:
Frequently Asked Questions
Should I use text/javascript or application/javascript?
According to RFC 9239, application/javascript is the official MIME type for JavaScript. However, text/javascript is still widely supported and used interchangeably. Most servers and browsers handle both correctly.
What MIME type should I use for ES modules?
ES modules use the same MIME type (text/javascript or application/javascript). The module behavior is determined by the type='module' attribute in the <script> tag, not the MIME type.