| Razor Optimizer - a New Approach to Light Up the Web |
|
| Tuesday, 12 August 2008 01:23 | |||||||||||||||||||||||||||||||
|
Razor Optimizer is a JavaScript optimization tool for reducing code footprint and increasing runtime performnace. As a cross-browser web application itself, Razor Optimizer can be access either online as a service, or to be downloaded to run locally. Razor Optimizer is based on a new approach for JavaScript optimization called "razor". While other optimization techniques such as JS minimization and concatenttion are based on static lexical analysis, Razor uses dynamic runtime profile information to achieve breakthrough results of 60% to 90% savings. Why Razor Optimizer? It is safe to say that Ajax is the technology foundation for Web 2.0. There are several hundred Ajax toolkits in the marketplace and new ones are still emerging. While Ajax is getting real popular over the web, what people may not know is that Ajax(JavaScript) code is becoming the top 1 or 2 factors to consider in terms of footprint and performance impact in relation to the overall site (or application). 40% to 70% of the footprint of today's typical web 2.0 sites is JavaScript. For example, the front page of FaceBook contains 532KB JavaScript, 77% of the page footprint. Ajax toolkits have also become more sophisticated and bigger. Developers are aware of the "code bloat" issue. Some developers choose to lower footprint by using shorter variable names and more compact code style. There are various optimization techniques available such as compression, JS minimization and file concatenation. All these are helpful, but none of them is helpful enough.
What can we do to bring Ajax to its full potential, and empower developers to use Ajax without worries?
Note that the problem is not new. Similar challenges exist for other programming languages. In early 2007, while studying Dojo performance, I blogged about "borrowing" approaches from other languages to optimize Ajax code(see Dojo Footprint and Ajax Performance Recommendation). At the time, I was hoping someone in the Dojo community would implement this. In late 2007 or early 2008, I remember seeing some research paper from Microsoft Research talking about something they call Razor Optimizer is based on a new approach coming from such kind of new thinking. Its goal is to free developers from the worries of code bloat, and free users from JavaScript introduced browser freezing. In one sentence, Razor Optimizer (hopes to) lights up the web!
Razor Optimization Features As an Ajax application itself, Razor Optimizer offers the following features:
How It Works Razor Optimizer itself is a web based JavaScript application that runs in any browser. It contains a server component and a client component. Razor Optimizer client is an Ajax application based on Dojo 1.1. Razor Optimizer Server is a Java web application that runs inside any Java Servlet container. The following figure shows the architecture of Razor Optimizer.
Razor Optimizer Architecture Razor Optimization Case Studies In general, Razor is able to reduce application footprint by 60% to 80%. The followings present three different application examples. The three applications are:
Table 2 shows optimization results for these three applications. Razor achieved 67%, 75% and 62% savings for them respective.
In comparison, Razor delivers significantly better results than other JavaScript optimization techniques. Using ShrinkSafe to optimize these three applications, the results would be 189KB, 568KB, and 86KB respectively (See Table 5). Razor further cuts down these numbers by half. The Idea Behind Razor Optimizer Razor is based on the following observations:
Wouldn't downloading one function at a time be very slow? Indeed. However, if you package a bunch of related functions together and if this one "package" is enough to fulfill one or more use scenarios, the user wouldn't notice any negative performance impact of incremental downloading. So the key to this approach is to understand when/which function is called during different runtime scenarios. For example, if we know exactly which functions are called and when they are called during the initial application loading, we can trim all other code from the initial download without breaking the application. This would significantly save the initial download size and improve page loading performance. The knowledge of “when/which function is executed” can be achieved by profiling the application. By recording the profile data, we can have accurate knowledge of the dynamic runtime behavior of the application beyond static lexical analysis for delivering breakthrough optimization results. How to Use It After you downloaded and installed Razor Optimizer (see instructions at GettingStartedWithRazor.html):
Razor Optimizer Screen Shot Try It out Razor Optimizer early beta is available for download. Try it out! Please comment below to let us know the problems you run into, complains or suggestions, etc.
|
|||||||||||||||||||||||||||||||
| Last Updated ( Wednesday, 04 February 2009 19:37 ) |