Mime Types Explained and Their Common Usage

Author

Reads 880

A young boy dressed as a mime focuses intently while taking photos with a smartphone.
Credit: pexels.com, A young boy dressed as a mime focuses intently while taking photos with a smartphone.

Mime types are a crucial part of the internet, helping browsers and servers understand the type of file being shared.

They're usually indicated by a dot followed by a series of letters, like .jpg or .pdf.

Mime types are used to determine how files are handled, whether it's opening in a browser, saving to a computer, or even executing a program.

For example, the .exe mime type is used for executable files, which are programs that can run on a computer.

Some mime types are used for specific types of files, like .mp3 for audio files or .mp4 for video files.

Mime types can also be used to prevent malicious files from being executed, by identifying them as a type that shouldn't be run.

The browser can then block the file from being opened, keeping the user safe.

A unique perspective: Webp Mime Type

Mime Type Structure

A MIME type most commonly consists of just two parts: a type and a subtype, separated by a slash (/) — with no whitespace between. This structure is case-insensitive, but traditionally written in lowercase.

Credit: youtube.com, Section 1 Module 1 Part 9: Mime Types & Content Type Headers (7:54)

The type represents the general category into which the data type falls, such as video or text. The subtype identifies the exact kind of data of the specified type the MIME type represents. For example, for the MIME type text, the subtype might be plain (plain text), html (HTML source code), or calendar (for iCalendar/.ics) files.

Each type has its own set of possible subtypes, and a MIME type always has both a type and a subtype, never just one or the other.

Discover more: Picture Mime Types

Structure

A MIME type is made up of two parts: a type and a subtype, separated by a slash (/) with no whitespace between them.

This structure is case-insensitive, but traditionally written in lowercase. For example, a MIME type like text/plain is a common example of this structure.

The type represents the general category into which the data type falls, such as video or text. You can add the optional charset parameter to specify the character set used for the characters in the data.

For instance, to specify a UTF-8 text file, the MIME type text/plain;charset=UTF-8 is used. This is because the default character set is ASCII (US-ASCII) unless overridden by the user agent's settings.

Types, subtypes, and parameter names are case-insensitive, but parameter values are usually case-sensitive.

Multipart

Credit: youtube.com, Understanding the Difference between Multipart and MIME Content Type

Multipart types indicate a category of document broken into pieces, often with different MIME types.

They can represent a composite document, like an email that includes a forwarded message as part of its data, using message/rfc822.

Multipart types can also be used to represent multiple, separate files which are all part of the same transaction, like data produced using the FormData API, which uses multipart/form-data.

This type of document is transmitted to the browser, which will likely show a "Save As" window if it doesn't know how to display the document.

There are two main types of multipart documents: a message that encapsulates other messages and data that consists of multiple components with different MIME types.

Multipart documents can be used to break a large message into smaller ones automatically to be reassembled by the recipient, using message/partial.

This is especially useful when sending very large messages in chunks as if it were multiple messages.

Mime

Credit: youtube.com, (8/36) Adding MIME Type on Your Domain

Mime is a crucial part of the mime type structure, and it's essential to understand how it works.

Some server configurations use the associated MIME type to perform optimizations, such as file concatenation, compression, or caching.

Most web servers send unrecognized resources as the application/octet-stream MIME type, which can limit user interaction.

The mime.types file is used to associate filename extensions with a MIME type, which is particularly helpful when the MIME type is incorrectly set or set to a generic type.

This file is usually located at /etc/mime.types and/or $HOME/.mime.types in UNIX-type systems.

Each line in the mime.types file is a space-delimited list of a MIME type, followed by zero or more extensions.

For example, the HTML type can be associated with the extensions .htm and .html by the following line:

On a similar theme: MIME Object Security Services

Mime Type Types

Mime types are broadly categorized into two main types: text and binary. Text mime types are used for plain text files, such as HTML, CSS, and JavaScript.

Binary mime types, on the other hand, are used for files that contain executable code or other non-text data, such as images, audio, and video files.

The most common binary mime types include image/jpeg, image/png, and audio/mpeg.

Application/Octet Stream

Credit: youtube.com, JSON file generated by PHP has application/octet-stream mime type

Application/Octet Stream is the default MIME type for binary files, which means unknown binary files. Browsers usually don't execute it, or even ask if it should be executed.

This type is treated as if the Content-Disposition header was set to attachment, proposing a "Save As" dialog. Most web servers send unrecognized resources as this MIME type.

For security reasons, most browsers don't allow setting a custom default action for such resources, forcing the user to save it to disk to use it.

Multipart/Byteranges

Multipart/Byteranges is a MIME type used to send partial responses to the browser.

It's triggered by the 206 Partial Content status code, which indicates that the document is composed of several parts.

Each part has a Content-Type header with its actual type and a Content-Range of the range it represents.

The Content-Type uses a boundary to separate the pieces, making it easy to distinguish between different parts of the document.

This type of MIME is useful for sending large files in smaller chunks, making it easier on the browser and reducing the risk of errors.

Legacy and Special Cases

Credit: youtube.com, Gramex FileHandler MIME Types

Legacy JavaScript MIME types are still supported by browsers for historical reasons. This means you can still use them, but it's not recommended.

There are several legacy MIME types that allow JavaScript to be served, including application/javascriptDeprecated and application/ecmascriptDeprecated. These types are deprecated, which means they're no longer recommended for use.

Here are some of the legacy JavaScript MIME types that are still supported:

  • application/javascriptDeprecated
  • application/ecmascriptDeprecated
  • application/x-ecmascriptNon-standard
  • application/x-javascriptNon-standard
  • text/ecmascriptDeprecated
  • text/javascript1.0Non-standard
  • text/javascript1.1Non-standard
  • text/javascript1.2Non-standard
  • text/javascript1.3Non-standard
  • text/javascript1.4Non-standard
  • text/javascript1.5Non-standard
  • text/jscriptNon-standard
  • text/livescriptNon-standard
  • text/x-ecmascriptNon-standard
  • text/x-javascriptNon-standard

It's worth noting that even though these types are supported, the recommended MIME type is text/javascript.

Legacy JavaScript

Legacy JavaScript is a thing of the past. The MIME Sniffing Standard allows JavaScript to be served using various legacy MIME types.

These types are still supported by some user agents, but it's not recommended to use them. Instead, stick with the guaranteed-to-work text/javascript MIME type.

You might be wondering why these legacy types exist. It's because of historical reasons, and they're now deprecated.

Here are some of the legacy JavaScript MIME types you should avoid using:

  • application/javascriptDeprecated
  • application/ecmascriptDeprecated
  • application/x-ecmascriptNon-standard
  • application/x-javascriptNon-standard
  • text/ecmascriptDeprecated
  • text/javascript1.0Non-standard
  • text/javascript1.1Non-standard
  • text/javascript1.2Non-standard
  • text/javascript1.3Non-standard
  • text/javascript1.4Non-standard
  • text/javascript1.5Non-standard
  • text/jscriptNon-standard
  • text/livescriptNon-standard
  • text/x-ecmascriptNon-standard
  • text/x-javascriptNon-standard

Remember, it's always best to use text/javascript for any JavaScript files.

Vendor Tree

Close-up Photo of Document Files
Credit: pexels.com, Close-up Photo of Document Files

The vendor tree is a collection of media types associated with publicly available products, and it's used to identify the producer or vendor of a specific software product. This tree is a crucial part of the IANA registry.

In the vendor tree, media types are prefixed with "vnd." and can be registered by anyone who needs to interchange files associated with some software product or set of products. Industry consortia, non-commercial entities, and even individuals can register media types in the vendor tree.

The terms "vendor" and "producer" are considered equivalent in the context of the vendor tree. This means that anyone who creates a media type in the vendor tree is essentially acting as the producer of that type.

Here are some examples of media types found in the vendor tree, as listed in the IANA registry:

  • application/vnd.ms-excel
  • application/vnd.oasis.opendocument.text

The vendor or organization producing the software that employs the type being registered can at any time elect to assert ownership of a registration done by a third party. This is an important aspect of the vendor tree, as it helps to ensure that the ownership of a media type is clear.

Mailcap

Black Iphone 4 Turned on Displaying Icons
Credit: pexels.com, Black Iphone 4 Turned on Displaying Icons

Mailcap is a type of meta file used to configure how MIME-aware applications render files of different MIME-types.

It's derived from the phrase "mail capability" and is supported by most Unix systems.

Mailcap is defined by RFC 1524, which outlines a user agent configuration mechanism for multimedia mail format information.

The format of a mailcap line can be a comment starting with the # character, or a mime-type followed by how to handle that mime type.

Netscape Use

Netscape used a mime.types file format that was different from the standard one. It employed key-value pairs and a comma-separated list of extensions, along with a specific comment header that identified the file as a mime.types file.

This Netscape format included a standard header with a comment that clearly marked the file as a mime.types file.

Terminology and Concepts

The terminology surrounding mime types can be a bit confusing, but it's essential to understand the different terms used in the industry. The IANA and IETF use the term "media type", while the WHATWG prefers "MIME type".

The term "MIME type" is still widely used, especially in contexts unrelated to email, such as HTTP. In fact, the W3C has used ContentType as an XML data-type name for a media type.

Linux desktop environments, as specified by XDG, also continue to use the term "MIME type".

Explore further: Media Type

Correct Type Setting

Close-up Photography of Smartphone Icons
Credit: pexels.com, Close-up Photography of Smartphone Icons

Setting the correct MIME type is crucial for server configurations to perform optimizations. Most web servers send unrecognized resources as the application/octet-stream MIME type.

Some server configurations compress files of certain MIME types, like in the Apache configuration example from h5bp/server-configs-apache. This can lead to significant file size reductions.

For security reasons, most browsers don't allow setting a custom default action for unrecognized resources, forcing users to save them to disk. This can lead to unnecessary file clutter.

Terminology

The term "media type" can be a bit confusing, especially since different organizations use it in slightly different ways. The IANA and IETF prefer the term "media type", but consider "MIME type" to be outdated.

The IANA and IETF's stance on "MIME type" is likely due to its origins in email contexts, which have expanded beyond that scope. In fact, media types are now used in HTTP contexts.

The WHATWG, on the other hand, still uses the term "MIME type" and advises against using "media type" due to its ambiguity. This is because "media type" has a different meaning in CSS.

The HTTP response header for providing the media type is called Content-Type. This is a crucial piece of information for web developers.

Linux desktop environments continue to use the term "MIME type", as specified in XDG specifications. This is a notable exception to the IANA and IETF's preferred terminology.

Common Examples and Usage

Credit: youtube.com, Understanding MIME Types

Mime types are used to identify the format of a file, and there are many common examples. The most widely used mime type is application/json, which is used for JSON data.

Some other common examples include application/ld+json (JSON-LD), used for structured data, and application/pdf, used for PDF documents. You'll also see application/vnd.ms-excel (.xls) and application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx) used for Excel files.

Here are some common mime types that you might encounter:

  • application/json
  • application/ld+json (JSON-LD)
  • application/pdf
  • application/vnd.ms-excel (.xls)
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx)
  • image/jpeg (.jpg, .jpeg, .jfif, .pjpeg, .pjp)
  • text/html
  • text/javascript(.js)

Sniffing

Sniffing is a browser behavior where it tries to guess the correct MIME type if the server doesn't provide one or if it thinks the provided type is incorrect. This can happen in certain cases, like when the browser is unsure about the file type.

Browsers perform MIME sniffing differently, and some even look at the file extension in the URL if the sent MIME type is unsuitable. For example, Safari will examine the file extension in the URL if the server's MIME type doesn't match.

Close-up of hands typing on a laptop keyboard with documents on a desk, brown long sleeves visible.
Credit: pexels.com, Close-up of hands typing on a laptop keyboard with documents on a desk, brown long sleeves visible.

Some browsers use filename suffixes, especially on Microsoft Windows, to determine the MIME type. However, not all operating systems consider these suffixes meaningful, and there's no guarantee they're correct.

Magic numbers, which are specific byte structures, can also be used to infer the file type. For instance, GIF files start with the hexadecimal value 47 49 46 38 39, and PNG files start with 89 50 4E 47.

Here are some ways browsers can guess the MIME type:

  • Filename suffixes (especially on Microsoft Windows)
  • Magic numbers (byte structures specific to file types)

Keep in mind that these methods aren't 100% reliable, and some file types may not have magic numbers.

Ruby

Ruby is a high-level, interpreted language that's known for its simplicity and ease of use. It's often used for web development, but can also be used for scripting and other tasks.

Ruby is a dynamic language, which means it doesn't require explicit type definitions for variables. This makes it a great choice for rapid prototyping and development.

Media and File Types

Credit: youtube.com, What is the correct MIME type for a tar.gz file?

Most web servers send unrecognized resources as the application/octet-stream MIME type. This can be a problem for security reasons, as most browsers don't allow setting a custom default action for such resources.

Some server configurations may use the associated MIME type to perform optimizations, such as file concatenation, compression, or caching. For example, an Apache configuration can compress files of certain MIME types, like the one found in h5bp/server-configs-apache.

MIME content types are used in MIME-compliant communications, like email or HTTP traffic, to indicate the type of content being transmitted. The mime-types library provides detailed information about MIME entities, which can be useful for determining the type of content.

Suffix

The +xml suffix has been defined since January 2001, and it's been formally included in the Structured Syntax Suffix Registry since January 2013. This means you should use it when registering media types that use a named structured syntax.

The +xml suffix is just one of many registered suffixes, including +json, +ber, +der, +fastinfoset, +wbxml, and +zip, which were all added to the registry in January 2013.

Audio and Video

Credit: youtube.com, Explaining Audio File Formats

Audio and video types have specific file types that are commonly supported by web browsers. These file types have special use cases, drawbacks, and compatibility information that's worth knowing.

Web browsers often support various audio and video codecs, which are listed in the audio codec and video codec guides. These guides provide technical information like the number of audio channels supported, compression type, and suitable bit rates.

The codecs used by WebRTC are specifically covered in the WebRTC guide, which is handy for choosing the best codecs to support a range of browsers. This guide helps you make informed decisions about codec selection.

MIME types of audio or video files typically specify the container format, or file type, and can include an optional codecs parameter to further specify the codecs and encoding options used. This parameter can include details like codec profile and level.

Intriguing read: Web Page Design Types

About Media

MIME types are used in MIME-compliant communications, like email or HTTP traffic, to indicate the type of content being transmitted.

Credit: youtube.com, Supported file types | Media Pro Tutorial

Some server configurations may use the associated MIME type to perform optimizations, such as file concatenation, compression, or caching. This can be seen in an Apache configuration that compresses files of certain MIME types.

MIME content types are determined by RFCs, W3C recommendations, the IANA Media Types registry, and user contributions. The mime-types library provides an enumerable collection of MIME::Type objects for detailed information.

Most web servers send unrecognized resources as the application/octet-stream MIME type. This can be a problem for security reasons, as most browsers don't allow setting a custom default action for such resources.

Audio and video types are often specified by their container format, or file type, which is typically indicated by a MIME type. For example, an MP4 file would have a MIME type of video/mp4.

The optional codecs parameter can be added to the MIME type to further specify which codecs to use and what options were used to encode the media, such as codec profile, level, or other such information.

Versioning and Lists

Credit: youtube.com, Demystifying MIME Types: A Guide to Declaration and Management

Versioning and Lists can be a bit tricky, but I've got some tips to help you out. For example, the `application/json` mime type is often used with JSON data, and it's a good idea to use a version number in the URL to keep track of changes, like `api/v1/data.json`.

When working with lists, it's essential to remember that some mime types, like `text/csv`, are designed for comma-separated values, and can be easily sorted and filtered. This makes them perfect for data analysis.

In particular, the `application/octet-stream` mime type is often used for binary data, and it's a good idea to include a version number in the filename to keep track of changes, like `data-v1.bin`.

3.x

Upgrading to 3.x is a good idea. Users are encouraged to do so as soon as possible.

mime-types 3.x requires Ruby 2.0 compatibility. This is a significant change from the previous version.

A simpler licensing scheme is also part of the upgrade. This makes it easier for developers to use the library.

MIME::Type::Columnar and MIME::Types::Columnar are considered private variant implementations. They should not be relied upon by users of the library.

Instead, depend on the public implementations (MIME::Type and MIME::Types). This is the recommended approach.

List

People Holding Dslr Cameras
Credit: pexels.com, People Holding Dslr Cameras

Versioning and Lists are crucial for keeping track of changes and organizing information.

The "MIME Types List" is a great example of a comprehensive list, covering all MIME types with detailed descriptions and links for further information.

Compiling a list like this can be a tedious task, but it's essential for clarity and understanding.

The author of the "MIME Types List" took the initiative to add names and descriptions to each MIME type, making it easier to navigate and understand.

A list should be a living document, updated regularly to reflect new information and changes.

If you think a list is missing elements, it's always best to contact the author or creator so they can update it accordingly.

Frequently Asked Questions

What is illegal MIME type?

An illegal MIME type is an invalid or improperly formatted email attachment type, often indicating a protocol anomaly or potential security issue. This can be caused by misconfigured software or malicious activity.

What is content type in MIME email?

Content type in MIME email refers to the format or type of data being sent, such as text, image, audio, or video. This helps email clients and servers understand how to handle and display the attached or embedded content.

How do I fix a MIME type error?

Adjust server settings to ensure correct MIME types are sent for all files, or manually specify the correct MIME type if transferring files between systems

Is PDF a MIME type?

PDF is not a MIME type, but rather a file format that has a designated MIME type of application/pdf. This MIME type ensures PDF files are handled correctly by applications and browsers.

Melba Kovacek

Writer

Melba Kovacek is a seasoned writer with a passion for shedding light on the complexities of modern technology. Her writing career spans a diverse range of topics, with a focus on exploring the intricacies of cloud services and their impact on users. With a keen eye for detail and a knack for simplifying complex concepts, Melba has established herself as a trusted voice in the tech journalism community.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.