What is MIME type "text/jsx"?
A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.
text/jsx denotes files that combine JavaScript with XML-like syntax. This is the JSX format used by modern web frameworks for building user interfaces.When a file uses JSX syntax, it mixes code and markup. Development tools then compile this into regular JavaScript for browsers. It does not run natively in browsers until it is transformed.
Files like TSX and ASTRO use this MIME type to signal that they contain JSX code. This helps editors and build systems apply the correct processing rules.
- JSX Integration: Allows mixing UI markup with JavaScript logic.
- Tooling Support: Enables syntax highlighting, linting, and compilation in development environments.
- Framework Usage: Common in projects involving React, Astro, and other modern libraries.
- Compilation Workflow: Requires a build step (e.g. using Babel) to convert the code into browser-ready JavaScript.
Learn more about MIME types on the MDN Web Docs.
Associated file extensions
Usage Examples
HTTP Header
When serving content with this MIME type, set the Content-Type header:
Content-Type: text/jsx
HTML
In HTML, you can specify the MIME type in various elements:
<a href="file.dat" type="text/jsx">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', 'text/jsx');
res.end('Content here');
}).listen(3000);
Associated file extensions
FAQs
Do web browsers natively support the text/jsx MIME type?
No, modern web browsers cannot execute text/jsx directly. This format is intended for development and must be transpiled (converted) into standard text/javascript using build tools like Babel or TypeScript before a browser can run it.
Why do I see an 'Unexpected token <' error when loading a script?
This error usually happens when a browser tries to read raw JSX code as regular JavaScript. If you are linking directly to a file with JSX syntax, you must compile it first. For quick prototyping without a build step, you can use a library like Babel standalone and set the script type to text/babel.
How do I configure Nginx or Apache to serve .jsx files?
While production environments usually serve compiled .js files, you can configure development servers to recognize the extension. In Apache, add AddType text/jsx .jsx to your config. In Nginx, add text/jsx jsx; inside the types { ... } block.
What is the difference between text/jsx and text/javascript?
text/javascript denotes standard, executable code that browsers understand immediately. text/jsx denotes source code containing XML-like syntax used by frameworks like React. The JSX file is the input for a build process, while the JavaScript file is the output.
Is text/jsx used for TypeScript files like .tsx?
Yes, development tools often associate TSX files with text/jsx or text/tsx to enable correct syntax highlighting and linting. Just like standard JSX, these files combine TypeScript logic with UI markup and require compilation.
Is text/jsx an official IANA standard?
No, text/jsx is not a registered media type with the IANA. It is a de facto standard used by editors, IDEs, and bundlers to identify files that require JSX transformation. For web delivery, always use standard types like application/javascript.
Does serving files as text/jsx present security risks?
Serving raw source code can expose logic or comments intended only for developers. Additionally, if you rely on client-side transformation of text/jsx, it may introduce Cross-Site Scripting (XSS) vulnerabilities if the transformer is not secure. It is best practice to compile code on the server side.
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.