Skip to content

Latest commit

 

History

History
82 lines (63 loc) · 4.96 KB

MIME hinting.md

File metadata and controls

82 lines (63 loc) · 4.96 KB

What is MIME Hinting and Why Does This Repo MIME hint?

This repo goes out of its way to MIME hint. To understand MIME hinting, you must consider the problem that it’s trying to solve. Ultimately, a Web site is a collection of files. Once those files are created, they must be given URLs. I want my site to be available under many different protocols, so eventually, each file will have multiple URLs each with a different scheme.

According to the HTML Standard,

“This specification uses the term document to refer to any use of HTML, ranging from short static documents to long essays or reports with rich multimedia, as well as to fully-fledged interactive applications. The term is used to refer both to Document objects and their descendant DOM trees, and to serialized byte streams using the HTML syntax or the XML syntax, depending on context.”

The HTML Standard, Section 2.1

This repo’s build system generates documents that will eventually be served over the Internet. The generated files and the data that gets served are “serialized byte streams using the HTML syntax”. That same section later goes on to say

“In the context of byte streams, the term HTML document refers to resources labeled as text/html, and the term XML document refers to resources labeled with an XML MIME type.”

The HTML Standard, Section 2.1

Strictly speaking, in order to be an HTML document, there must be something that labels these byte streams with a text/html MIME type.

Additionally, an HTML document’s MIME type may specify that the charset is UTF-8.

Here’s the problem: you can never be certain that the MIME type is correct. Consider this question: how do you specify a MIME type? For one thing, it depends on what scheme your using:

This suggests that an HTML document’s MIME type should be self-evident. In other words, the computer should be able to detect the MIME type by looking only at the file’s contents because there’s no guarantee that the scheme we’re using provides a MIME type.

For the sake of argument, let’s say that we’re using a scheme like http or data which provides a MIME type for the file. Even then, the MIME type should be self-evident. Consider this: how does an HTTP server determine what gets put in the Content-Type header? The server probably looks at the file to figure it out. I’m sure it would be possible to manually specify MIME types, but that still doesn’t guarantee that they’ll be correct.

MIME hinting is the act of including information in a file to make its MIME type self-evident. Throughout this repo, you’ll find comments that say “MIME hint note:”. Those comments will contain explanations of how MIME hinting is done.

SPDX-FileNotice: The “HTML Standard” by WHATWG (Apple, Google, Mozilla, Microsoft) is licensed under CC BY 4.0.