MIME Types

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

1

Common Use

External JavaScript files loaded via <script> tags

2

Common Use

JavaScript module files

3

Common Use

Server-side JavaScript responses

4

Common Use

CDN-hosted library files

Examples

Server Configuration

Serve files with the text/javascript MIME type:

# Nginx
location ~ \.js$ {
  add_header Content-Type "text/javascript";
}

# Apache
AddType text/javascript .js
HTML Usage

Use 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.