Blog, COLDSURF

mimetype

MIME Type (IANA Media Type)

  • A media type (or MIME type) indicates the nature and format of a document, file, or byte stream.
  • Browsers use MIME types, not file extensions, to determine how to process a URL. Therefore, it's crucial for the web server to send the correct MIME type in the Content-Type header of the response. If this is not configured correctly, the browser may misinterpret the file contents, causing the site to malfunction, and the downloaded file might be processed incorrectly.

Structure of MIME Type

A MIME type is generally composed of two parts: type and subtype, separated by a slash (/). There is no space between these parts.
type/subtype
  • type: A general category to which the data type belongs, such as video or text.
  • subtype: Identifies the specific type of data that the MIME type represents. For example:
    • For text, the subtypes could be plain, html, or calendar.
  • Each type has unique subtypes. A MIME type always consists of both a type and a subtype; it does not contain only one or the other.
  • Additional optional parameters may be added to provide more detailed information.
type/subtype;parameter=value

Important MIME Types for Web Developers

  • application/octet-stream
    • The default for binary files.
  • text/plain
    • The default for text files.
  • text/css
    • CSS files that define styles for a webpage should be of type text/css. If the server does not recognize files with a .css extension as CSS, it may send them with the MIME type text/plain or application/octet-stream. In such cases, most browsers will fail to recognize the file as a CSS file and quietly ignore it.
  • text/html
    • All HTML content should be served with this MIME type. Alternative MIME types like application/xml+html for XHTML are rarely used nowadays.
  • text/javascript
    • JavaScript content should be served with the MIME type text/javascript. Other MIME types will not be considered valid for JavaScript, and using anything other than text/javascript could prevent the script from loading or executing.

ETC

MIME type stands for Multipurpose Internet Mail Extensions, which is a standard format that defines the data format for email. MIME types were developed to enable the transmission of binary data, such as images, videos, and Excel files, over email systems that could originally only transmit ASCII code. Today, MIME types are used in HTTP communication to identify the format of data.
ā† Go home