Slash Boxes

SoylentNews is people

posted by martyb on Sunday February 23 2020, @10:30AM   Printer-friendly

Helsinki-based software developer, Henri Sivonen, has written a pair of blog posts about UTF-8; why it should be used and how to inform the user agent when it is used.

The first blog post explains problems that can arise when UTF-8 is used without explicitly stating so. Here is a short selection from Why Supporting Unlabeled UTF-8 in HTML on the Web Would Be Problematic:

UTF-8 has won. Yet, Web authors have to opt in to having browsers treat HTML as UTF-8 instead of the browsers Just Doing the Right Thing by default. Why?

I'm writing this down in comprehensive form, because otherwise I will keep rewriting unsatisfactory partial explanations repeatedly as bug comments again and again. For more on how to label, see another writeup.

Legacy Content Won't Be Opting Out

First of all, there is the "Support Existing Content" design principle. Browsers can't just default to UTF-8 and have HTML documents encoded in legacy encodings opt out of UTF-8, because there is unlabeled legacy content, and we can't realistically expect the legacy content to be actively maintained to add opt-outs now. If we are to keep supporting such legacy content, the assumption we have to start with is that unlabeled content could be in a legacy encoding.

In this regard, <meta charset=utf-8> is just like <!DOCTYPE html> and <meta name="viewport" content="width=device-width, initial-scale=1">. Everyone wants newly-authored content to use UTF-8, the No-Quirks Mode (better known as the Standards Mode), and to work well on small screens. Yet, every single newly-authored HTML document has to explicitly opt in to all three, since it isn't realistic to get all legacy pages to opt out.

The second blog post explains how one explicitly communicates to the user agent that UTF-8 is employed in the current document. Always Use UTF-8 & Always Label Your HTML Saying So:

To avoid having to deal with escapes (other than for , &, and "), to avoid data loss in form submission, to avoid XSS when serving user-provided content, and to comply with the HTML Standard, always encode your HTML as UTF-8. Furthermore, in order to let browsers know that the document is UTF-8-encoded, always label it as such. To label your document, you need to do at least one of the following:

  • Put as the first thing after the start tag (i.e. as the first child of head).

    The meta tag, including its ending > character needs to be within the first 1024 bytes of the file. Putting it right after is the easiest way to get this right. Do not put comments before .

  • Configure your server to send the header Content-Type: text/html; charset=utf-8 on the HTTP layer.

  • Start the document with the UTF-8 BOM, i.e. the bytes 0xEF, 0xBB, and 0xBF.

Doing more than one of these is OK.

NB: SoylentNews announced UTF-8 support on 2014-08-18: Site Update: Slashcode 14.08 - Now With UTF-8 Support (And Other News), just 6 months after the site was launched! One of our developers volunteered to do the implementation for them (the code for this site is a fork of the code that underlies slashdot). The offer was declined. A quick check before posting this story still fails to show Unicode/UTF-8 support.

Earlier on SN:
Validating UTF-8 Strings Using As Little As 0.7 Cycles Per Byte (2018)
Announcing UTF-8 Support on SoylentNews (2014)

Original Submission

This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 3, Funny) by FatPhil on Sunday February 23 2020, @12:43PM (4 children)

    by FatPhil (863) <reversethis-{if.fdsa} {ta} {tnelyos-cp}> on Sunday February 23 2020, @12:43PM (#961376) Homepage
    Heck, I know I'm going down in flames, so I might as well get something else off my chest...

    Anyone who uses:
        -webkit-font-feature-settings: 'liga' 1, 'dlig' 1, 'kern' 1;
        -moz-font-feature-settings: 'liga' 1, 'dlig' 1, 'kern' 1;
        -ms-font-feature-settings: 'liga' 1, 'dlig' 1, 'kern' 1;
        -o-font-feature-settings: 'liga' 1, 'dlig' 1, 'kern' 1;
        font-feature-settings: 'liga' 1, 'dlig' 1, 'kern' 1;
    is a complete tosser. That's from Sivonen's home page. Nothing uglifies webpages than those horrible 'st' ligatures.

    But that doesn't make his arguments wrong, of course. It's just that he's outed himself as a tosser, nothing more.
    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    Starting Score:    1  point
    Moderation   +1  
       Funny=1, Total=1
    Extra 'Funny' Modifier   0  
    Karma-Bonus Modifier   +1  

    Total Score:   3  
  • (Score: 2) by takyon on Sunday February 23 2020, @12:58PM (1 child)

    by takyon (881) <> on Sunday February 23 2020, @12:58PM (#961380) Journal

    I have not seen that. Is that in the CSS standard? []

    CSS Fonts Module Level 3
    The definition of 'font-feature-settings' in that specification. Candidate Recommendation

    [SIG] 10/28/2017: Soylent Upgrade v14 []
    • (Score: 0) by Anonymous Coward on Sunday February 23 2020, @07:18PM

      by Anonymous Coward on Sunday February 23 2020, @07:18PM (#961509)

      I have not seen that. Is that in the CSS standard?

      Most likely not, because all of these:

      • -webkit-font-feature-settings:
      • -moz-font-feature-settings:
      • -ms-font-feature-settings:
      • -o-font-feature-settings:

      Are rendering engine specific CSS style flags to allow for new styles flags to be 'tested' before incorporation in the standards. Note these web standards are really only 'standards' in the most basic sense. The reality is that they are "lets make a common standard for what all the various engines are already doing, differently". I.e., a real world example of this XKCD: XKCD on Standards [].

      So this last one:

      • font-feature-settings:

      Is likely what will end up getting incorporated into some later revision of CSS. But for now it is ignored and one of the others turns the miss-feature on in your particular browser. But reality is that st litagure is so damn ugly the whole bit should be tossed into the dust bin and forgotten.

  • (Score: 2, Interesting) by Anonymous Coward on Sunday February 23 2020, @12:58PM

    by Anonymous Coward on Sunday February 23 2020, @12:58PM (#961381)

    +1 a thousand times.

    I had to go into dev tools and turn off those awful stylings to make the page readable.

    Those css styles simply should not exist.

  • (Score: 2) by maxwell demon on Sunday February 23 2020, @01:55PM

    by maxwell demon (1608) on Sunday February 23 2020, @01:55PM (#961389) Journal

    Yeah, replace "dlig" 1 with "dlig" 0, and everything gets readable again.

    The Tao of math: The numbers you can count are not the real numbers.