Skip to content

application/javascript MIME Type — Meaning, Usage & Examples

application/javascript
Extensions: .js, .mjs Class: application Spec: RFC 4329 (IANA registered)
View IANA registration ↗

application/javascript means: application/javascript is the registered media type for JavaScript source code, the scripting language of the web. Browsers execute scripts served with a JavaScript type; RFC 4329 defines application/javascript and documents the older text/javascript alias for compatibility. Application media types carry structured or binary data that a program consumes rather than a human reading raw bytes. The subtype tells the receiver exactly which parser, decoder or handler to invoke, so sending the correct Content-Type is part of the API contract: a mismatch makes servers reject the body with 415 Unsupported Media Type or clients mis-parse the payload. You will encounter application/javascript in contexts such as external script files loaded via script tags or es module imports; javascript bundles emitted by build tools and served from cdns; service workers and module scripts that require a correct js type. It is commonly associated with the file extension(s) .js, .mjs. ES modules are strict about MIME type: a module script served as text/plain or text/html is blocked with a MIME-type error. Use application/javascript (or text/javascript) and the correct charset; never serve executable code as a generic type.

Advertisement
Ad slot · ref-top

When you'll see application/javascript

  • External script files loaded via script tags or ES module imports
  • JavaScript bundles emitted by build tools and served from CDNs
  • Service workers and module scripts that require a correct JS type

How to handle it

When handling an application type, set the Content-Type header explicitly on every request and response that carries a body, and advertise what you accept with the Accept header. Parse the payload with a library that matches the subtype rather than sniffing bytes, and validate the structure before trusting it. If a server returns 415, the declared type does not match what it expects — compare your header against the API documentation character for character, including parameters such as charset or boundary. As a final checklist for application types: register the exact subtype in your API documentation, validate incoming bodies against a schema before use, set X-Content-Type-Options: nosniff to stop MIME sniffing, and version your media types when the payload contract changes so old clients keep working.

Notes & gotchas

ES modules are strict about MIME type: a module script served as text/plain or text/html is blocked with a MIME-type error. Use application/javascript (or text/javascript) and the correct charset; never serve executable code as a generic type.

Examples

HTTP
HTTP/1.1 200 OK
Content-Type: application/javascript
Content-Length: 58

export function greet(name) {
  return `Hello, ${name}`;
}
curl
curl -i -H "Accept: application/javascript" https://api.example.com/v1/resource   # inspect the returned Content-Type
JavaScript (fetch)
// ES modules require a JavaScript MIME type or the import is blocked.
const mod = await import("./module.js");   // server must send application/javascript
mod.greet("Ada");
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource",
                   headers={"Accept": "application/javascript"}, timeout=10)
res.raise_for_status()
# confirm the server declared the expected type
assert res.headers["Content-Type"].startswith("application/javascript")
text = res.text   # decode/handle according to the type

Frequently asked questions

Is text/javascript still valid?

Yes, RFC 4329 treats text/javascript as a legacy alias of application/javascript. Both work, but application/javascript is the recommended registered form for new systems.

Why does my module script fail to load?

Browsers enforce a JavaScript MIME type for ES modules. If the server returns text/html (e.g. a SPA fallback for a missing file) the import is blocked — check the actual Content-Type and the file path.

What happens if I send the wrong application Content-Type?

Servers that validate media types answer 415 Unsupported Media Type, and clients may parse the body with the wrong decoder. Always set Content-Type to the registered type that matches your payload, and set Accept to the types you can handle.

Is application/octet-stream a safe default?

It means 'arbitrary binary bytes' and forces a download rather than inline handling. Use it only when the real type is unknown or you deliberately want a save-as dialog; otherwise declare the specific registered type.

How do I debug a 415 Unsupported Media Type response?

Compare the Content-Type you actually sent against what the endpoint documents, including parameters like charset and boundary. A 415 means the server refuses that media type; send the exact registered type it accepts and retry.

Advertisement
Ad slot · ref-in-article

Try the JSON Formatter

Beautify, validate and minify JSON with clear error messages.

Open tool →