5

W3C has ended support for the polyglot markup. So do I have to convert my site to use regular HTML5 instead of XHTML? How would them abandoning this concept affect existing sites? I want to have a perfectly valid markup and if that code conflicts with what is the standard, I will have to remove it.

Johny P.
  • 648
  • 1
  • 9
  • 31
  • The individual syntaxes are still valid. You can use the HTML or the XHTML syntax of HTML5 as you prefer, serving them as `text/html` or `application/xhtml+xml` respectively. But, given that all modern browsers support both media types, there's really no use for a spec that describes how a single document can be treated as either syntax. – Alohci Apr 19 '16 at 07:19
  • The current official specification of HTML includes all polyglot features (slash in void elements is optional in text/html documents, same for the xmlns attribute etc) so effectively, this overrides the polyglot specs, making it unnecessary to maintain a separate document for that. By the way, I have no idea why you think they're giving up on XHTML. The W3C validator will keep on supporting XHTML, etc. – Mr Lister Apr 19 '16 at 09:55
  • Unless you mean you're currently serving up your XHTML files as text/html, in which case I can only raise my eyebrows. – Mr Lister Apr 19 '16 at 10:01
  • Actually, yes I do serve my XHTML as `text/html` since IE8 and below won't display it at all if it were `application/xhtml+xml`... I could use php to detect IE and send the appropriate `header`, but still the browser string can be changed to whatever the viewer wants so I don't find this solution viable. – Johny P. Apr 19 '16 at 12:14
  • 1
    In that case, the polyglot spec is not at all relevant to you. So yes you should convert your site to use regular HTML5 instead of XHTML. The problem with serving your "perfectly valid" XHTML as `text/html` is that the browser is treating it as invalid tag soup. – Alohci Apr 19 '16 at 12:42
  • @Alohci That's what I'm going to do then. – Johny P. Apr 19 '16 at 13:39

1 Answers1

5

As usual more bashing in comments against XHTML without any true comprehension of what it is.

  • XHTML uses the XML parser.
  • HTML uses the HTML parser.

  • The XML parser is strict, it is an application with low tolerance for error.
  • The HTML parser is relaxed and doesn't mind if the screen door is open on your submarine.

You can and should use the strictest tools available to you. In example in PHP you should always check if a variable isset. Why? Hackers will remove an input element from a form, submit the form and then try to see what error messages the server would send. But if you lower the strictness of PHP's error messages you would think everything is fine and dandy.

I saw a guy stress out for three days over why only Safari wouldn't render a certain style correctly. If he had used the XML parser the page would have (in Firefox) completely failed and he would have gotten an error message pointing out exactly what the error is, what line it's on and what column on that line (other browsers render up to the line so use Firefox for testing by default). His error? He was missing a double quote around one of his attributes; the screen door was wide open on his submarine.

This does not imply you can't use HTML5 because we're talking syntax here. Ideally you should be using XHTML5, HTML5 using the XML parser. It doesn't catch all issues (duplicate id attribute values in example) though it will require you to code on a higher level.

Yeah, IE8 doesn't support XHTML (it kind of supports XML) but it's not even worth considering supporting IE8. Frankly it's the only browser that has any "significant" market share that doesn't support XHTML though this doesn't mean you can't do content negotiation:

<?php
if (stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml'))
{
 header('Content-Type: application/xhtml+xml');
 echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
}
?>

Keep in mind that IE8 will render in quirks mode if it sees the XML declaration though as of 2016 that is a moot point since it's no longer a browser worth supporting unless you're being paid as a specialist specifically to deal with that browser.

My whole platform uses XHTML5 and it has greatly improved standards, development time and skillset. Always question the integrity of people who speak against doing something that requires more skill, there is a reason why the saying a dime a dozen exists.


If you're looking for a quick way to adapt usage of the XML parser though don't have the time to replace dozens or hundreds of <br> in example I highly recommend considering Advanced Find and Replace. Pick a directory, one or several file types (e.g. *.php;*.css;*.xml) and the code you want to find and then what to replace with. Additionally it actually runs faster emulated via Wine that Linux's native grep command and it's super cheap. Do be careful how you do mass find-and-replaces though, the stricter your code's white-space the better off you'll be and always back things up first!

John
  • 1
  • 13
  • 98
  • 177
  • 1
    Actually if it were a site for me, I'd frankly not care about IE5-9 at all and serve my site as `application/xhtml+xml` in XHTML5... But I'm getting paid to make a site for a huge hotel company and I can't afford them to lose clients. Certainly not when there's money involved. – Johny P. Apr 27 '16 at 11:09
  • But I will have what you said in mind when I re-design my site next time. – Johny P. Apr 27 '16 at 11:56
  • Then just omit the XML declaration for IE8 and lower. Then instead of using *any* CSS hacks just use the following: https://www.jabcreations.com/web/css/ieccss and best of luck! – John Apr 27 '16 at 15:51
  • Besides having HTML and XML parsers browsers also render either in quirks mode or standards mode. IE8 and older aren't able to comprehend XML (except for very difficult to produce results) so the XML declaration throws IE8- in to quirks mode. So just serve the XML declaration when PHP also serves the age as `application/xhtml+xml`; I'll update the answer to reflect that. – John Apr 27 '16 at 16:34
  • 1
    I don't see any XHTML bashing in the comments on the question o_O – BoltClock Apr 27 '16 at 16:40
  • Well, I guess now that you have made it clear for me that I can serve real XHTML5 to both IE and all other major browsers and have the expected output, I think it's worth the investment to go back to XHTML5... I'll be adding trailing slashes to void elements in the next few hours :D – Johny P. Apr 27 '16 at 18:52
  • Oh, almost forgot just to use HTML5 (regardless of media type/mime) you'll need to use the HTML5 shiv: https://github.com/aFarkas/html5shiv – John Apr 28 '16 at 03:46
  • If you're going to use content negotiation, don't forget to set the `Vary:` header to stop proxies serving your `application/xhtml+xml` content from their caches to IE8. – Alohci May 01 '16 at 00:26