Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

response header VS meta tag

I can declare some info, like encoding and language, in meta-tag or in response-header.
My question: what the best way (maybe them both), for SEO and old-browsers?

meta-tag example:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

(PHP) header example:

header('Content-Type: text/html; charset=utf-8');

What's better ?

like image 751
Dani-Br Avatar asked Feb 23 '12 16:02

Dani-Br


People also ask

What is a response header used for?

A response header is an HTTP header that can be used in an HTTP response and that doesn't relate to the content of the message. Response headers, like Age , Location or Server are used to give a more detailed context of the response.

What is header and metadata?

Metadata is "data about data" and the header in files such as HTML, WAV, MP3, text, etc contain a header, which defines the data within the file.

What is the difference between request headers and response headers?

Request headers contain more information about the resource to be fetched, or about the client requesting the resource. Response headers hold additional information about the response, like its location or about the server providing it.

Do meta tags have to be in the header?

<meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings. Metadata will not be displayed on the page, but is machine parsable.


2 Answers

Do both. The header takes precedence, but if the HTML page is accessed locally, there are no HTTP-headers, so you want to have <meta charset="..."> as a safety mechanism.

like image 152
Šime Vidas Avatar answered Oct 02 '22 03:10

Šime Vidas


Meta http-equiv is little more than a joke. When specifying Content-Type with it, only the charset section counts for anything, and then only when the real HTTP headers fail to specify the encoding.

like image 34
Quentin Avatar answered Oct 02 '22 02:10

Quentin