WebReference.com - Part 1 of Chapter 21: Professional JavaScript, from Wrox Press Ltd (1/6) | WebReference

WebReference.com - Part 1 of Chapter 21: Professional JavaScript, from Wrox Press Ltd (1/6)

current pageTo page 2To page 3To page 4To page 5To page 6
[next]

Professional JavaScript 2nd Edition

Why do it in JavaScript?

One of the popular uses of Java is to build animated effects that can be embedded into a web page. Many applets provide button rollovers and menu handlers, or are used for news headline scrolls and tickers.

The major problem with all of this, is that there is a certain penalty involved in deploying these applets. The problem is that for many browser and platform combinations, the time taken for the Java Virtual Machine (JVM) to start up can be a nuisance. Also, if the applet requires a later version of the JVM, then that has to be installed as well. In its worst-case scenario, the JVM start-up can completely suspend the page loading and drawing process, meaning that the user can sometimes stare at an empty or unchanging screen for 30 seconds or more.

Using frames can alleviate this, but can still be frustrating. So, the challenge is to create a news ticker using JavaScript. It needs to be dynamically data driven and start-up very quickly.

When we look at an example like this, there is a temptation to suggest that there must surely be a very simple solution. We will see though that the result is something that did evolve from a simple solution, but has become complex as a necessity. The complexity comes from discovering shortcomings in the support of dynamic effects on different versions of browsers. Different platforms also exhibit failure modes that force us to code round the problem, sometimes in a sub-optimal way.

Simplicity is possible if you can bind your target audience with code that works on a very restricted platform and browser combination. However, portability dictates that we need to go the other way and accommodate many versions of many browsers on many platforms. That clearly must add complexity given the current state of the JavaScript and DOM implementations.

The Platform Issue

Right away, we bump into some difficult problems. Any dynamic effects are not likely to be browser independent. This kind of dynamism on Netscape prior to version 6, is going to rely on layers and may not be feasible at all, (that's assuming we are going to totally disregard browsers earlier than Netscape 4). With layers, we might be able to create some dynamic effects, but that would have to take place within the main content area of the page. Constraining the boundaries of the layer to fit exactly the right location and size, were also considered to be quite a difficult problem to solve in the context of the News Online front page where the ticker was intended to be used. On those grounds, and also being aware that even in 1999 layers were already considered a deprecated feature, we decided not to attempt to provide Netscape 4.x JavaScript driven tickers. We already had the Java ticker that was working on Netscape anyway.

On IE, we had Dynamic HTML techniques available to us to replace the content of a tagged block of HTML marked-up text.

Looking at the traffic figures for the BBC News Online site, we established at the outset that Netscape 4 accounted for less than 15% of the traffic. Most of our traffic was attributable to IE. This itself was quite a shock, as it clearly indicates the extent to which Microsoft now dominates the browser marketplace and the extent to which Netscape have lost market share.

Looking again at the figures 2 years on, Netscape 6 penetration is still very small at around 0.3% (as of summer 2001). Making special provision for Netscape 6, is very hard to justify from a commercial or resource allocation point of view. In the meantime, Netscape 4 browsers are rapidly declining in use. Arguably, the Holy Grail of a single platform is mostly within reach at the expense of it all being under Microsoft's control. Even that is a vain hope, because IE is implemented quite differently on Macintosh and Windows, and will only be available on platforms that Microsoft sees commercial benefit in supporting. There is no long-term alternative other than approaching the problem from a standards-driven perspective. In 1999, that was not viable, but it is now looking more attractive.

All of this dictated the design goal of getting this ticker working on IE and basically disregarding the other browsers since they could continue to use the Java applet, albeit with the 30 second delay for the Java VM.


current pageTo page 2To page 3To page 4To page 5To page 6
[next]

Created: November 5, 2001
Revised: November 5, 2001


URL: http://webreference.com/programming/javascript/professional/chap21/1/