What is MIME type "application/x-javascript"?
A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.
application/x-javascript signals that a file contains JavaScript code. It informs the browser to execute the script rather than display it as plain text. This MIME type is used by files like JS.
Its main role is to enable interactive and dynamic behavior on web pages. The script can update content, respond to user actions, and communicate with servers—all on the client side.
- Dynamic Behavior: Scripts update and change webpage content without requiring a full page reload.
- Client-Side Processing: JavaScript handles user input, validates forms, and manages events directly in the browser.
- Legacy and Compatibility: Though modern sites often use text/javascript, many servers and browsers still recognize this MIME type.
Additional details are available at the MDN Web Docs on JavaScript.
Associated file extensions
Usage Examples
HTTP Header
When serving content with this MIME type, set the Content-Type header:
Content-Type: application/x-javascript
HTML
In HTML, you can specify the MIME type in various elements:
<a href="file.dat" type="application/x-javascript">Download file</a>
Server-side (Node.js)
Setting the Content-Type header in Node.js:
const http = require('http');
http.createServer((req, res) => {
res.setHeader('Content-Type', 'application/x-javascript');
res.end('Content here');
}).listen(3000);
Associated file extensions
FAQs
Is application/x-javascript the standard MIME type for JavaScript?
No, application/x-javascript is considered obsolete; the current official standard is text/javascript. However, because it was widely used in the past, almost all web browsers still recognize and execute code served with this MIME type for backward compatibility.
What is the difference between application/x-javascript and text/javascript?
The application/x-javascript type was an experimental label (indicated by the x- prefix) used before standard bodies finalized the definition. text/javascript is now the canonical IANA standard defined in RFC 9239. Functionally, browsers treat them identically, but you should prefer the standard text version for new projects.
How do I configure Apache to serve .js files with this MIME type?
If you specifically need this legacy type, add AddType application/x-javascript .js to your .htaccess or httpd.conf file. However, it is highly recommended to use the standard configuration AddType text/javascript .js unless you are supporting very old user agents that do not understand the text subtype.
Why does my browser console show a warning about the MIME type?
Browsers often warn if a script is loaded with a generic type like text/plain or if the X-Content-Type-Options: nosniff header is present but the MIME type doesn't match a valid JavaScript type. Ensure your server is sending a recognized JavaScript MIME type (like text/javascript, application/javascript, or application/x-javascript) to resolve these execution blocks.
Can I use application/x-javascript to serve JSON data?
No, you should strictly use application/json for JSON data. Serving JSON as application/x-javascript allows the data to be executed as code, which can lead to security vulnerabilities known as JSON hijacking or cross-site script inclusion (XSSI) attacks.
Does Nginx support application/x-javascript by default?
Most default Nginx mime.types files map the .js extension to application/javascript or text/javascript. If you need to force application/x-javascript, you must manually edit the mime.types file or add a types { application/x-javascript js; } block within your server configuration.
General FAQ
What is a MIME type?
A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.
MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.
How do I find the MIME type for a file?
You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.
Why are multiple MIME types listed for one extension?
Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.