Jump to content

Mime Type


atar.yosef

Recommended Posts

Hello to all the fellows!!!During my studies at the W3school's great HTML tutorial I encounter again and again with the concept who called "MIME Type".This concept is very myterious for me and I don't succeed to understand about what it mention and what it is essence.Can someone help me with this?

Link to comment
Share on other sites

On your computer, files end with the so called "extension". For example ".txt", which lets your computer know this is a text file, or ".jpg", which lets your computer know this is a JPEG image file. You should know by now that depending on the extension, your computer reads the file differently. If you were to rename a ".txt" file to ".html" file, it will open up in your browser instead of opening in Notepad.On the web, the concept of "extension" is not appropriate, because regardless of what you type in your address bar, if it starts with "http:", your browser must render something on the screen or show you a download box if it can't display it. Take for example the homepage of every site, e.g.http://w3schools.com/and compare it to any non home page, e.g.http://w3schools.com/about/default.aspDo you see any extension on the home page? And what about the second... how is the browser supposed to render an ".asp" file? MIME types are part of the solution to this problem... anyway...To solve this problem, as well as a few other ones, which I'll avoid mentioning to keep it simple, the "http" protocol splits the content in two parts - headers and body.The "body" is the content that your browser (or any HTTP client) receives. In the example of a ".txt" file above, that would be the contents of the text file itself. Even if you were to rename the file to ".html", the body is still the contents of the file.What "headers" are (very roughly put) is a bunch of text that tells the HTTP client how to process the content. Each "header" is a line. For example, part of the HTTP headers for the home page of W3Schools looks like:

HTTP/1.1 200 OKContent-Length: 24418Content-Type: text/html

In this excerpt, there are two headers - "Content-Length", and "Content-Type". The first line is not a header, but it's a part of the headers section. Each header has a name (everything before ":"), and a value (everything after the ":").The "Content-Length" header tells the HTTP client the length of the body. The HTTP client ignores everything from that many bytes after the body starts. I believe there was a feature known as "pipelining", where after that many bytes, the HTTP client will start process a second response, but I'm not sure about this...And we come to the "Content-Type". In case you haven't guessed already, this tells the HTTP client the type of content it is dealing with, similarly to the extensions on your computer's files. Instead of ".html" however, you see "text/html" as the value of that header. This "text/html" value is a MIME type. Other valid values for the "Content-Type" header are also MIME types. Similarly to the file extensions, they tell the HTTP client how to process the body. "text/html" means the HTTP client should process the body as an HTML file, and "text/plain" would mean the browser should process the body as a text file.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...