Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the importance of correct MIME types?

Tags:

html

mime

In my Chrome I am getting these warnings:

Resource interpreted as stylesheet but transferred with MIME type text/plain.
Resource interpreted as script but transferred with MIME type text/html.
pngResource interpreted as image but transferred with MIME type text/plain.

Why should I care? Or what is the probability that there is a browser that wouldn't treat the resource as the main browsers do?

like image 544
Jader Dias Avatar asked Jan 11 '10 11:01

Jader Dias


People also ask

What does a MIME type do?

A MIME type (now properly called "media type", but also sometimes "content type") is a string sent along with a file indicating the type of the file (describing the content format, for example, a sound file might be labeled audio/ogg , or an image file image/png ).

How are MIME types determined?

MIME types are defined by three attributes: language (lang), encoding (enc), and content-type (type). At least one of these attributes must be present for each type. The most commonly used attribute is type. The server frequently considers the type when deciding how to generate the response to the client.

What is a correct MIME type for pdf?

The main MIME media type for PDF is application/pdf. This type is defined by RFC 8118 and is the responsibility of ISO TC 171 SC 2 WG 8. It was last updated in March 2017, prior to the original publication of PDF 2.0, so the PDF Association is proposing a minor refresh and update in the upcoming May 2022 ISO meetings.


2 Answers

Serving files with an incorrect mime type can open up security holes. Here's a high profile example.

like image 74
Tobu Avatar answered Sep 21 '22 18:09

Tobu


MIME types let the browser know what each file is. Browsers associate other applications, helper applications/extensions to handle certain MIME types. So, setting the correct MIME types will let the browser handle the object/file the way it was meant to be done.

like image 42
Alan Haggai Alavi Avatar answered Sep 20 '22 18:09

Alan Haggai Alavi