Utilo

EPUB MIME Type – Free, Online, Private

application/epub+zip is the type for an EPUB book. The file is a ZIP whose first entry is the ASCII string mimetype.

What .epub is

EPUB is a ZIP package with a required layout. The first entry, uncompressed, is the file mimetype and its contents are the ASCII string application/epub+zip. That entry existing is how a sniffer confirms the package without trusting the HTTP header. META-INF/container.xml points at the package document, which lists the XHTML content documents, styles, and images. Those inner documents are XHTML and CSS. They are not separate responses while they live inside the book. IANA registers application/epub+zip for the package. application/zip is what you get if you ignore the spec, and some readers will still open it, and some will not.

IANA registers application/epub+zip. The media type is application/epub+zip. Extensions that use it on this page: .epub. A client compares the type, not the filename, once the response has arrived. The filename still matters on disk and in Content-Disposition, which is why a wrong extension and a wrong header are two different bugs.

What sends application/epub+zip

What sends application/epub+zip: Send application/epub+zip for a .epub download. Set a filename ending in .epub. Do not add a charset. The container is binary. The inner XHTML is UTF-8 by the EPUB rules. Do not gzip the whole response and drop Content-Encoding. Readers check the first bytes for PK and then for the mimetype entry. A transfer encoding the client does not reverse will fail that check. Range requests help a reader fetch the central directory and the package document without the fonts and images. The file on disk is still .epub. Once the response exists, a client trusts application/epub+zip, not the filename. If you also sell a PDF, that file is application/pdf on its own URL. Do not content-negotiate the book format on one path without Vary. A cache that serves the EPUB bytes to a client that asked for PDF is a corrupt download with a confident type.

Content-Type for .epub

Send application/epub+zip and do not add a charset parameter. The body is binary. A charset tells a text decoder to reinterpret bytes that are not text, which corrupts a download and does not help a browser sniff the format.

Content-TypeContent-Type: application/epub+zip

nginx, Apache, and Express

These snippets map .epub to application/epub+zip. nginx reads the types block when it picks a type from the URL's extension. A location that sets default_type, or an application that sets the header itself, overrides that map. Apache AddType applies in the directory context where you put it. The Express static example writes the header for files ending in .epub so a stale mime database in the framework cannot disagree with the type on this page.

nginx# /etc/nginx/mime.types, inside the types { } block
application/epub+zip        epub;
ApacheAddType application/epub+zip .epub
Expressimport express from "express";

const app = express();
app.use(express.static("public", {
  setHeaders(res, filePath) {
    if (filePath.endsWith(".epub")) {
      res.setHeader("Content-Type", "application/epub+zip");
    }
  },
}));

Pitfalls for application/epub+zip

Pitfalls that show up for application/epub+zip, and not for a neighboring type with a similar extension: The mimetype entry must be first and uncompressed. A zipper that sorts entries alphabetically or compresses everything produces a file that is a valid ZIP and an invalid EPUB. The HTTP type being correct does not repair the package. Another trap is serving the book as application/zip, which a browser unpacks. Another is an XHTML content document that is not well-formed. The reader fails mid-chapter. Another is a download URL that returns an HTML store page with a 200. The client saves the store page as a book. Check the PK magic before you call the response a success in your own tests.

  • application/epub+zip is the registered type. application/epub is not the one to send.
  • The first ZIP entry is the uncompressed ASCII file mimetype containing application/epub+zip.
  • Inner chapters are XHTML. The HTTP response for the book is still this type, not text/html.
  • application/zip is the generic container and a worse choice for a reader that switches on the specific type.

Frequently asked questions

What is the Content-Type?

application/epub+zip.

What has to be inside the ZIP?

The first entry is an uncompressed file named mimetype whose body is the ASCII string application/epub+zip. container.xml points at the package.

Can I send application/zip?

A ZIP tool will open it. EPUB readers look for application/epub+zip. Send the specific type.

Are the chapters text/html?

They are XHTML parts inside the package. The HTTP response that delivers the book is application/epub+zip.