IE 10 to drop conditionals
Written by Ian Elliot   
Friday, 08 July 2011

The HTML conditional is no more and the real problem is how to replace it. JavaScript is one way but this isn't always appropriate. Vendor-specific CSS seems to be catching on as another way. but this is a mess and hardly an improvement.

Of course exact standardization is always welcome, but there is always the problem of breaking old code by dropping past indiscretions in favour of standards exactitude - i.e. if you do it right now you might well break past code that depends on doing it a little wrong. When something is an addition to a standard then there is often the temptation to let things slip and stay as they are. Not so with Microsoft and IE10.

ie10logo

In a recent blog post it was revealed that some widely used legacy constructs are about to be dumped. The most important is the removal of support for the conditionals that come into play if your HTML contains anything like:

<!--[if IE]>
other HTML that will only render
if the browser is HTML
<![endif]-->

Conditionals are used in many pages to take account of strange behavior of past browsers - notably IE6. The whole point of a conditional is that it takes the form of a valid HTML comment which IE takes notice off as a command where the others treat it as a comment. You have to admit that it is a nice construct and a safe way of including additional functionality.

But having comments actually do something is the road to madness and Microsoft is going to eliminate them in IE10. As from IE10 you have to use the more modern approach of feature detection rather than browser identification.

The argument goes that this is no great loss as conditionals will still work in older browsers and in IE10 in legacy mode - just not in IE10 native mode. As conditionals are mostly used to make up for problems with older browsers this should all work as expected. However, don't use conditionals in any page that used HTML5 as a short cut to avoid feature and environment detection.

So everything is fine. Well there is one small problem. HTML5 doesn't have a conditional to replace it with. This isn't unreasonable as HTML is just a markup language, and a semantic markup language at that. It isn't supposed to have actions and so conditionals are out.

Unfortunately what this means is that you have to resort to JavaScript or something on the server side. The point is that without a conditional facility in HTML5 you have no choice but to make what was a simple task handed over to the browser's parser into one where you now have to write some active code. You have gone from a 100% HTML solution to HTML+JavaScript - and what if JavaScript is turned off?

An alternative to HTML+JavaScript is to use conditional CSS - but this most probably means using vendor-specific properties. It is a little known fact that the CSS standards can be extended by custom properties and it is still legal. All custom properties start with - and if the browser doesn't recognize the property then it ignores it. So for example:

-moz-border-radius

is a property that is only processed if the browser is from the Mozilla family (Gecko-based browsers) and ignored otherwise.

Hold on a moment, isn't this exactly the same sort of mechanism that has just been dropped by IE10 and HTML5 in general? So what isn't good for HTML5 is good for CSS.

More worryingly have you actually looked at the number of custom CSS properties? It's a growing sprawling mess that makes a nonsense of the idea of feature detection. See With the number of experimental features supported it is not only a mess it's a fragile mess destined to make web pages look silly in future browsers.

This doesn't smell good.

A simple HTML conditional that made use of either browser or feature conditions would be a great simplification. Why doesn't HTML5 have such a feature?

Because theoretical purity rules over practical simplicity.

It's not so much that IE10 needs to lose conditionals, more that HTML5 needs to find them.

 

 

If you would like to be informed about new articles on I Programmer you can either follow us on Twitter or Facebook or you can subscribe to our weekly newsletter.

 

Banner


HTML Templates For dtSearch
31/03/2014

The newly released dtSearch 7.5 adds HTML5 templates for publishing data on the Web in a searchable format.



Festo's BionicKangaroo
05/04/2014

Festo is renowned for building amazing robotics platforms that are based on nature and the latest, a hopping kangaroo that is controlled by gesture, is another masterpiece of engineering.


More News

Last Updated ( Friday, 08 July 2011 )
 
 

   
RSS feed of news items only
I Programmer News
Copyright © 2014 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.