12 July 06

Javascript Libraries and the future of Javascript

Javascript is dead. Long live Javascript.

The recent web 2.0 phenomenon reignited the spark that Javascript had been lacking for a few years. Between ‘web 1.0’ and ‘web 2.0’, Javascript was as popular as a Global Hypercolor t-shirt, but what with Ajax and the resurgence of DHTML, the popularity sharply increased and every new “web application” was using Javascript somewhere.

All this increased Javascript means heavier pages, and we have seen Javascript libraries such as Prototype and jQuery been used a lot more frequently. These libraries are generally used to cut down time on code, making it easier and quicker to do the 80% of things you need to do. This is an almost Rails-y type of way of thinking about these libraries.

These libraries however do add a considerable and noticable effect on loading times, especially when used in conjunction with other add-ons and plug-ins. For instance, an uncompressed Prototype script is 48k, and Rails’ default Javascript tag (which include Prototype) add a whopping 146k to a page.

I imagine that using old skool scripting for pages currently using large libraries would see their weight considerable drop. Using the $ function is very useful, but I presume that most people would not use most of the library.

However, this is true with Javascript, and with any language for that matter. Most of the core elements don’t get used. The difference between this and Javascript libraries is that Javascript libraries still have to be downloaded.

Is there any way of overcoming this? To still have the usefulness of Javascript libraries without the download weight of them? Well, currently, no.

On the very distant horizon, there is Javascript 2.0, but this won’t be implemented into browsers for a few years yet. Mozilla think it will be 2010 until certain browsers catch up (have a guess at which one it could be?), but this could be possibly longer.

A possible way of using the current Javascript libraries to counter-act this time lag could be through extensions. In a similar way to how Flash works and upgrades, there could be a plug-in or maybe a Firefox extension to keep the Javascript libraries on your computer without constantly needing to download the same scripts.

This would ensure that the latest versions of Javascript could be used. We only have to look at the adoption rate of Flash Player to show that even the most Actionscript versions are on over 70% of computers. Seeing as Actionscript and Javascript are both based on ECMAScript, I can’t see any reason why we can’t have a similar system.

It would be nice not to download the same 40k+ file every time we visit a site with Prototype, but even if we didn’t have some kind of plug-in/extension, we could still use the Javascript – albeit having to download the library.

Two major downsides in having an extension like this are security risks – kiddie scripters pretending that their ‘library’ is a proper download – and backwards compatibility.

We don’t know if Javascript libraries manufacturers are to support backwards compatibility or not, so how are we to know what version of the library will work with a plug-in or not. Obviously the best way around this would be to have unobtrusive Javascript, but that would just be wishful thinking, considering the state of the web at the moment.

Let’s hope that in the future, we have the functionality of these libraries without the need for download. For the present, let’s just hope that we don’t see a continuation of script abuse. 50k for a simple show/hide mechanism is ridiculous.

Remember kids, Javascript is enhancement, not a user burden.

Related reading:

Enjoy this? Subscribe to the feed for the very latest updates.

Comments

Comment by John Resig on 13 July 2006, 06:29

Hi Rik – I just wanted to stop by to clarify a couple points: jQuery is a complete library, and only 14k in size. All extraneous components (such as animations or ajax) are optional. jQuery takes backwards compatibility very seriously – keeping an open dialog with all plugin developers concerning issues that they encounter, and any changes that may come to the API. Let me know if this helps to clear up any questions that you had.

Comment by Rik on 13 July 2006, 10:01

Hi John, thanks for clearing up those points. I knew jQuery is quite light – in fact, I will be doing a .net article on it soon, but I have seen people using it for very simple things (e.g. show and hide). It seems like although libraries are simple to use, they may affect the user through downloading scripts they don’t necessarily need. Why have a 1k script + jQuery/Prototype, when a 2k script will do?

Hopefully, developers will not forget the Javascript basics through using libraries, as it is a lot easier to use them!

Add your comment

Back to top — © Rik Lomas 2006-2008 all rights reserved.
No part may be reproduced without the written permission of the copyright owner, unless otherwise stated