Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid a character set in the meta tag AND Specify a character set

I have alredy add code in my php web page like...

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

than after in https://developers.google.com/speed suggest for

  • Specify a character set
  • Avoid a character set in the meta tag
like image 262
anand bhoraniya Avatar asked Apr 27 '13 11:04

anand bhoraniya


People also ask

What is character set in meta tag?

The charset attribute specifies the character encoding for the HTML document. The HTML5 specification encourages web developers to use the UTF-8 character set, which covers almost all of the characters and symbols in the world!

How do you define a character set?

A character set is an encoding system to let computers know how to recognize Character, including letters, numbers, punctuation marks, and whitespace.

What is character set How many types of character set?

A character set is a system for representing languages in data. Where binary data can include any sequence of 0s and 1s, text data is restricted to a set of binary sequences that is each interpreted as a character from a language. The following are common types of character set.

What is the purpose of character set and different character sets?

A character set refers to the composite number of different characters that are being used and supported by a computer software and hardware. It consists of codes, bit pattern or natural numbers used in defining some particular character.


1 Answers

Use a HTTP header rather than a meta tag. Implementing that depends on what server-side tech you are using.

If you are generating your content using PHP, put this at the top of your page:

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

If you are using any other server-side programming language, there must be a similar option.

Alternatively, if you are using Apache, you can do it using htaccess directives as follows:

AddType 'text/html; charset=UTF-8' html

And if you're using nginx, put this in your config:

more_set_headers -t 'text/html' 'Content-Type: text/html; charset=utf-8';

More on the meta tag "avoidance"

Google dev tools suggest removing meta tags wherever possible due to the information duplication that it may cause. Some webservers automatically send content-type headers, for example, and in some cases, incoherent meta tags can cause browsers to get... shall we say, confused.

To avoid duplication of information and possible charset-related headaches, always prefer headers over meta tags.

like image 95
Sébastien Renauld Avatar answered Sep 28 '22 02:09

Sébastien Renauld