April 16th, 2009 §
Browser sniffing doesn’t work. It may have started out as a way to distinguish functions supported by different browsers, but it is now the devil.
Back in the old days when there are only Netscape and IE, it was the norm to detect Either-Or and serve different versions, but today, there are dozens of browsers, and each with many different versions with many different support level.
For example, browser-makers are adding new CSS3 support in every version update, by browser detection, you are almost dommed to failure as at some point, a browser that does not support a particular CSS3 will eventually(support it).
Today, there are still sites which use EOT, Embedded Open Type fonts. This is Microsoft’s dynamic fonts, whereby users don’t need to have the fonts and can download immediately when some sites need it. The catch is that it is only supported in Windows platform. Another dynamic font is PFR, which was promoted by the now defunct Netscape browser.
Many sites started using these dynamic fonts out of necessity. Back then, unicode support was not the best and many sites with non-western encoding had to resort to dynamic fonts to solve the problem. However, today, unicode is already capable of displaying all language encodings. And if you want special font style, standardized web fonts(using @font-face in CSS) is the answer.

Because of legacy reasons, sites such as eenadu.net shown above still uses EOT and PFR to display Telugu fonts. Therefore, non-Windows users will not be able to pleasure of reading sites like this, unless of course non-Windows users take the hassle to download the dynamic fonts manually.
September 29th, 2008 Comments Off
Broswer sniffing doesn’t work. Browser sniffing may have started out as a way to prevent browsers without proper features from accessing the sites, but now it often keeps browsers away from sites which otherwise would have worked.
In the old days, sniffing was often seen as a necessary way of coping with browser incompatibilities, but it was never meant to be a long-term solution. No sooner did you finish your site, a new version of an old browser came along to break it.
Browser sniffing was invented because different browsers had wildly varying DOMs so authors neeeded to send one script to one browser, and another to a competing browser. The browser incompatabiliites eventually led to the Web Standards movement, which showed that correctly-written specs and technologies that followed them is a more robust way for different browsers to interoperate.
The reason that the old way was not robust was because it was because designing a site should be like designing a car without worrying about driving on incompatible roads. Designers want to master their art, and browsers should make sure designers are given the right to express themselves in a standard way. When browser-of-the-day is not standard compliant, developers will design according to that dominant browser even if it is not compliant. This not only breaks other browsers, but future version of the same browser. So, for example, if Internet Explorer 8 were to run on its “standard mode”, it will break many sites that worked fine in previous versions of Internet Explorer.
Browser sniffing also creates a catch-22. In order to access a site that blocks your browser, you made your browser disguise itself as a supported browser. This was done by changing the user agent string that a browser sends the server when it requests the page, so your unsupported browser appeared to the server to be another. And so it became self-perpetuating: when the developer looked at his statistics and realized that he has only one browser visiting the site, he thought that there was no reason to bother designing for other browsers.
Even though that way of working is discredited, and all modern browsers can render sites perfectly if they’re made with web standards, some people still use browser sniffing. To get round it, Opera uses user and browser JavaScript to mask ourselves. Google Chrome uses another method. It has the longest user agent string anyone has ever seen, thereby telling the world that it is 1) Mozilla 2) WebKit, 3) KHTML, 4) Gecko, 5) Safari and 6) itself:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.X.Y.Z Safari/525.13
At Opera our experience is that the majority sites that block us actual worked fine in Opera, and those that don’t can be “repaired” with a healthy spoon of standard-compliant code.
The best way forward is to drop browser sniffing and design with web standards in mind. This way your website will run on browsers across the board, and it will work in the future.
Originally posted in ODIN.
September 23rd, 2008 §
Google Chrome惊动四方,一个“不小心”把文件泄露了,搞得大家都等不及它的推出。 Google当然不负众望,成功加入了一个竞争非常的软件领域=浏览器。Google的加入,再一度引起了大家对浏览器世界的关注。除了微软IE,还有开源的Firefox,北欧Opera,苹果Safari。当然,在中文世界里,还有Maxthon. 顿时另浏览器拉锯战再一次燃起火花。IE虽然称霸已久,可是确实在性能方面的表现不尽如人意(不敢恭维)有某方面做得不太完善,特别是对web标准的支持。它之所以还是霸主,和软件绑定不无关系。
微软从当年的95%到当今的70%证明了游览器市场还是会持续的变化。更何况当年微软也是从网景的垄断抢了过来。现在我们又看到了Google Chrome的加入,火狐新推出新的Trace Monkey JavaScript,还有Opera 9.6测试版都一再显示浏览器的市场占有可能会一再改变。在这种情况下,已经不是IE独领风搔,而是百花齐放。在这种情况之下,很多程序员都不禁问到,是不是时候设计给所有网站,而非单单IE而已呢? 答案绝对是,而且严格来说,每一个版本的IE都可以算是一个不同的浏览器,有不同的排版引擎(rendering engine),JavaScript引擎。现在微软竭尽全力,想把IE8规格化,可是却出现了一个很致命的问题,很多专为IE7和6设计的网站不符合规格,在这种情况下,微软就变得进退不得,结果就得靠不一样的排版来显示IE6,IE7和IE8网站。
举例来说,web标准addEventListener, 其他游览器都可以支持,可是唯独IE不行。在这种情况下,程序员除了给其他符合web标准的游览器(绝大多数的游览器)用addEventListener,也得给IE加上一个微软本身支持的attachevent。当然如果是特别个案就算了,不过还有很多CSS element,比如content property在IE7也是不被支持的。
现在微软要解决web标准问题,提议大家用不同的meta/doctype来告诉浏览器,排版引擎哪些用IE8的,哪些用IE7的。当年网景和微软之战,即使网景当年拥有绝大多数的市场(估计不少于95%),可是最后市场也吹向IE。那想想,如果今后IE下台,换来另一个霸主,那程序员的网站岂不是要从新更改。更何况,在很多海外市场,人们已经不偏爱IE。在印尼火狐是龙头。而且在手机游览器这块肥田,Opera是佼佼者,更有挪威资料称Opera的占有率已经超过一半。
而且试想想,现在IE可能要求人家用meta或doctype(甚至是别的方法)来区别网页到底是用哪个排版引擎。个人觉得是一个不错的选择,毕竟这是要同一时间让设计者可以用web标准来设计,又要确保旧有网站可以兼容的唯一方法。不过令人疑惑的是,程序员是否愿意在每一页放doctype呢?用CSS来设定吧,不过也得很头痛的。
一个网站有了大量的CSS,HTML, Javascript就开始会出现某些性能不能在两个网站一起运行。在中国,IE和Maxthon是占市场很大比率,那给她们他们的排版设计好了(毕竟IE和Maxthon用一样的排版,不过就象之前提到的,非常不标准化。可是很多网站的使用者,特别是web2.0网站的使用者,都相信选择(freedom of choice),毕竟除了IE,还有火狐, Opera, Safari, Chrome, Omniweb, Konquerer, Camino, Chrome等。这些使用者,也是消费群,而且更可能是肯花钱的一群,因为她们他们选择了使用更前端的科技,更能接受新思维,那也或许更可能接受网上消费(或已经在做了)。比方,手机浏览(另人联想到3G)的霸主可不是IE。
IE8将问世,那些运用了不规格的网站可以靠不同排版解决,不过大家可以想像未来IE9呢?IE10呢?以往大家或许有的好理由用不规格的设计,毕竟IE市场如此之大。不过笔者相信再未来其他浏览器也会陆续提供选择,大家都会开始接受不同的的CHOICE。唯有运用web标准设计,才可以给所有用户提供最佳的浏览经验,最好的网站设计。