Content Type

From Seobility Wiki
Jump to: navigation, search

Content type – Definition & explanation

The content-type header is an identifier used to tell the HTTP client or server what the media/file type of a resource is. Content-type is also called the media type or the MIME (Multipurpose Internet Mail Extensions) type.

Specifying the content type helps the user agent understand what type of content it is, improving the user experience by displaying content in the best possible fashion.

Why is content type used?

The content-type header indicates the type of media/file in communication between the HTTP client and the server. It helps the browser or server understand what format the information being sent/requested is in, improving the way it is processed and displayed.

When content type is used in a request by the client, it tells the server what media types it is looking for. Although the server doesn’t have to adhere to the request, it can help it find the right resources and return them in the desired format, if possible.

When resources are sent from the server to the client, the content-type header indicates what type of content it is receiving. This helps the browser prioritize resources and know when to render them, potentially improving the page speed.

Even though the file extension provides some information, it doesn’t always offer enough, which is why the content-type header is used.

Directives

There are three directives required for the content-type header, namely:

  • Media type – The resource’s MIME type,
  • Charset – The character encoding standard
  • Boundary – Only required for multi-part entities. Used to encapsulate the boundaries of the different parts of the message.

Media types

There are a large number of different media types that can be used when setting the content type. Below are some of the most common ones, but a full list can be found on Iana.org.

  • application/pdf
  • application/xml
  • audio/ogg
  • audio/mpeg
  • image/apng
  • image/jpeg (.jpg, .jpeg, .jfif, .pjpeg, .pjp)
  • text/css
  • text/html
  • text/php
  • text/xml
  • video/mp4

Browser compatibility

The content-type header is supported by most major browsers, namely:

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari
  • Opera
  • Samsung Internet Browser

MIME Sniffing

MIME sniffing is when browsers use the content instead of the content-type header to gauge the MIME type. MIME sniffing means the browser doesn’t follow the content-type header. This can be problematic in some cases, potentially creating a security risk. This can be prevented by using the no-sniff response header.

In the past, Google has requested web developers to use the no-sniff response header in a bid to prevent browser hacks [1]. Not doing so may lead to vulnerabilities that result in a poor user experience.

Code syntax example

Content-Type: text/html; charset=UTF-8
Content-Type: multipart/form-data; boundary=something

Importance for SEO

The content-type header isn’t a major part of SEO, but there are some important features that can impact a site’s search engine performance. By implementing best practices, an improved user experience and website security can be achieved, which, in turn, can help improve your site’s performance in the SERPs.

References

  1. Google Asks Publishers to Add Nosniff Response Headers Search Engine Journal. Retrieved 02 May 2021.

Related links

Similar articles