I think web specifications have become too complex. I'm trying, really I am, to conform to XHTML 1.1 (why? just because). I've pretty much concluded that this is just all too complex and time-consuming for any but the most supremely anal-retentive people with nearly unlimited free time to be certain that their page conforms to all the relevant specifications. The W3C's validator doesn't even check if the Content-type returned by an XHTML 1.x page is 'application/xhtml+xml', which has a "SHOULD" level of necessity in the spec.
Besides content types, there are character encodings, which have to be specified in two or three places (and then the actual encoding of the page content has to be correct), and the language of a page, which can be specified in a few different ways, and I'm not yet certain which way is the correct one. Plus, it's actually fairly hard to edit pages by hand and be sure that they're valid XHTML 1.1.
What a mess.
Oh great, the (X)HTML validator is broken. I use a variation of Mark Pilgrim's code to check if the user-agent supports 'application/xhtml+xml':
<?php
if(strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
header("Content-type: application/xhtml+xml");
else
header("Content-type: text/html");
?>
The validator must not be sending an 'application/xhtml+xml' Accept header, because my page is being returned as text/html. The validator then complains that I have no DOCTYPE declaration, even though I'm using one of the declarations included in their list. If I unconditionally return the page with an 'application/xhtml+xml' Content-type, the validator correctly validates the page. What's going on here?
Update: It turns out there's an error in Mozilla's "view source" feature! I couldn't figure out why my page wasn't validating. I tried validating Simon's page, which validated. I finally checked the "show source" feature of the validator, and it turned out I was getting the following PHP notice (reformatted slightly):
<br />
<b>Notice</b>: Undefined index: HTTP_ACCEPT
in <b>[filename]</b> on line <b>2</b><br />
which Mozilla's "view source" didn't show! It just showed three blank lines at the top of the page. It turns out that the validator doesn't send any Accept header at all, so I changed the above code to (reformatted slightly):
<?php
if(isset($_SERVER['HTTP_ACCEPT']) and
strpos($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml') !== false)
header("Content-type: application/xhtml+xml");
else
header("Content-type: text/html");
?>
And that made it work.
I've almost decided that viewing PHP's notices are more trouble than they're worth. Any code I release should be developed with as strict a level of error messages as possible, but there's no reason I should have to put up with it in my code if I don't want to. Though, it's not clear how to develop with strict errors on without all my pages having that level of error messages.
Update: Maybe rather than going straight to 'text/html' I should be going to something like 'text/xml' first.
There's a lot more to conditional get and HTTP caching than If-None-Match and Etag headers.
new⇒I hate ASP.NET
CF, why pick that piece of trash?Cold Confusion. Is it finallyreally a OO...
ColdConfusion: Sep 5, 8:36pm