JavaScript/jQuery versus Actionscript/Flex : Take 1  

Monday, November 16 2009

As part of my ongoing adventures in Flash I have began to work with more and more with Actionscript 3.0 and Adobe Flex. Having come from a strong Javascript/jQuery background I can’t help but compare the two technologies as they are both client-side scripting languages based on the ECMA standard.

There are numerous differences between these two sets of technologies. I’m not going to attempt to cover all of these differences, I just want to highlight some of the issues I find particularly compelling.

Browser penetration

Actionscript / Flex

This is perhaps one of the biggest considerations. In order to run a Flex application, the browser must have Flash Player 9 or above installed. Adobe brag’s that Flash has over 99% market penetration in the US Adobe.com, but frankly this is just not true.

There are millions of users who have never installed Flash, don’t know what Flash is, don’t have the security privileges to install any browser plugins, or are on mobile device that doesn’t support flash. Overall Flash has a large market penetration, but you need to consider your target audience and not just assume they will all have the correct version of Flash installed.

Javascript / jQuery

Unless your users are running NOSCRIPT or a similar JavaScript blocking software your Javascript / jQuery code is going to load, if that code works is an entirely different story.

Portability

Actionscript / Flex

If your Flex application works on one machine, it’s going to work on every machine that has the same version of the Flash player. Since Flex applications all run in the same Actionscript Virtual Machine they almost always behave the same regardless of the computer / browser. Unless you have strict control of every machine which is going to run your application, this is a HUGE benefit.

Javascript / jQuery

:-(

jQuery has done remarkable things to allow cross-browser development, but the bottom line is that there are multiple html rendering engines and they all hate you. jQuery has done a remarkable job normalizing the quirks between rendering engines, but if you are building any serious application YOU WILL run into cross browser issues. All JS developers have at least one story where they had an epic battle with IE6 or Safari or Firefox or Chrome or Opera….

Performance

Actionscript / Flex

If you need to do any heavy duty stuff (millions of records, animations, streaming data) you want to use Flex. The performance of the AVM isn’t great, but it’s going to outperform the browser’s JavaScript implementation every time (sorry V8, you don’t count).

Javascript / jQuery

You can get some great performance out of jQuery (if utilized correctly). It’s very possible to build extremely rich user interfaces with CSS, HTML and jQuery but there is a limit. HTML5 is still a long way aways and <canvas> isn’t all that great to begin with. If you think you are going to be pushing the limits of the browser, you need to consider switching to Flex. If this isn’t an option you need to test early, and often. Do not assume that your grid control will behave the same with 1,000 records as it did with 100. Do not assume that because your code runs lightning fast in Firefox, that Internet Explorer will run equally as fast (or at all for that matter). The browser loves to eat up 99% cpu.

Streaming Data

Actionscript / Flex

Flex has tcp/ip sockets. This means you can perform real-time data streaming, just like a real application. Adobe is very committed to allowing real-time data to stream to Flex applications and they have dedicated products, protocols, and lots and lots of documentation. Push technology is very much supported and works well.

Javascript / jQuery

Good luck with that. Javascript doesn’t support sockets. Any solution you implement is going to be long-polling. If you are serious about streaming data you MUST understand the concept of Comet . I would highly suggest using a Comet framework and not implementing your own. I’ve had to build an asynchronous message queue using jQuery and raw PHP, I wouldn’t recommend that anyone do this. Read up on Comet, again READ UP ON COMET. Streaming data to the browser is not out of the question by any means, but you will have to do the research and pick an appropriate server side software.

Conclusion

In no means am I trying to advocate one technology over the other. Personally, I love working with JavaScript and jQuery. I also like riding my bicycle. This is not to say that if I had to travel 500 miles I wouldn’t want to rent a car with satellite radio, gps, and air conditioning.

Remember in the end, it’s simply about evaluating your project’s requirements and making the suitable choice.

In Take 2 of this series I will begin to talk more about actual programming practices and implementations.


  • Posted by Marak Squires