SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2014
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trying to Understand Content-Type

    I am reading the FAQ section in this forum and I have seen this:


    Can I set the MIME type with a <meta/> tag?
    No. A user agent needs to know the content type before it starts parsing the response body. When it encounters an element like this, it's already too late:
    HTML Code:

    <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>

    The MIME type must be sent as a Content-Type HTTP header. The character encoding should be specified in the XML declaration (see above).



    Nevertheless, if I open the code of this same forum, I find this meta:

    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

    Can anyone explain it to me please?

    Thanks very much.

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by jonathan_M View Post
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />

    Can anyone explain it to me please?

    Thanks very much.
    We do that to set the charset only. The MIME type in that line is indeed ignored, but the charset is not. HTML5 has officially allowed us to shorten that line to only the parts that matter:

    <meta charset="ISO-8859-1">
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    The meta tags are often read *IF* the server did not send an appropriate header.

    The meta tag setting the charset is also ignored if the server sent a different one.
    If neither server headers nor meta tags for something are present, the user agent (browser) gets to guess, or use some internally-selected default. IE6 used to use heuristics to guess the charset of a page, after which it would then start re-rendering the page all over again.

    It's considered good practice to have a charset meta tag as a backup anyway, even though stuff like the UTF-7 hack are very very unlikely : )


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •