Home Razor Optimizer Description
Razor Optimizer - a New Approach to Light Up the Web PDF Print E-mail
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 "Donoto" (unfortunately I couldn't find any information about Denoto on the web. If you know it, please post it in comments) "Doloto" (see http://research.microsoft.com/projects/doloto/. Thanks Stephen Lamm).


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:

  • Runs in any browser
  • Works with any Ajax application and Ajax toolkit
  • A built-in profiler that records and visualizes application runtime profile data;
  • Full automated, no programming required
  • Detailed result reporting with comparison to other optimization techniques
  • Light up your app with 50% to 90% footprint reduction
  • Reduce the number of network round trips


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 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:

  1. American Airline’s web site (http://www.aa.com): this site uses PrototypeJS JavaScript library, one of the popular Ajax toolkits;
  2. Razor Optimizer itself: Razor Optimizer is a Dojo 1.1 based JavaScript application;
  3. jQueryUI demo (http://ui.jquery.com/functional_demos/): this is an application based on the popular jQuery library.

Table 1: Applications to be Optimized
Ajax toolkit Total JavaScript footprint (byte)
www.aa.com Prototype JS 294,124
Razor Optimizer Dojo Toolkit 1,158,664
jQuery UI Demo jQuery 151,151

Table 2 shows optimization results for these three applications. Razor achieved 67%, 75% and 62% savings for them respective.
Table 2: Razor Optimization Results
Original (byte) Razor Optimized(byte) Savings
www.aa.com 294,124 96,735 67%
Razor Optimizer 1,158,664 292,203 75%
jQuery UI Demo 151,151 56,904 62%


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:

  1. JavaScript functions are the basic low level building blocks of JavaScript code. Though typical JavaScript applications are made up of JavaScript files, functions are at a lower level than files because each JavaScript file is composed of JavaScript functions. While current JavaScript optimization techniques operates on a “file” level, performing optimization at the function level could yield much better result;
  2. At any moment of time, the browser needs only one function because only one JavaScript function is executed at any moment of time.
  3. Theoretically, the application would work fine if we download only one function at a time, right before the function is going to be called. Other functions are not needed. They can stay on the server side without being downloaded until they are going to be called. There is no need to download all the code up front, and there no need to download them at once;
  4. If only one function needs to be downloaded and stay on the client side, we can achieve breakthrough savings in both download size as well as client memory/CPU footprint, resulting in significant performance improvements above any other techniques.
The basic idea of Razor is to “trim” the “not needed” functions and only download these functions that are necessary for a specific usage scenario. This “trimming” process is called “raze”. After the initial download, if a “razed” function is needed, Razor will download this function on demand in the background.

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):

  1. Start Razor server;
  2. Open a browser instance and visit URL http://localhost:9090 to launch Optimizer UI;
  3. Click "New Session" to start a new session. You may need to login. If you don't have an account, register one;
  4. Enter the URL of your application, for example, http://ajaxian.com. This URL must be accessible from the Razor Server instance you are using;
  5. Razor will attempt to open a new browser window to launch your application. Make sure that you configured your popup blocker to allow it to so do.
  6. Your application will be running in its own browser window. Just click around your application (try to stay on the same page though, because multi-page scenarios have not been tested enough for Razor Optimizer).
  7. At the meantime, Razor is recording profile data in the background;
  8. Click "Close and View Results" to finish profiling.
  9. Click "Optimize" to configure optimization. From here, you can configure file concatenation, ordering, function preservation, etc.
  10. Finally, click "Optimize it now" to perform optimization. Razor server will process your code and generate a report in the end that shows you optimization results. You can download the results as a ZIP file;
  11. Deploy the ZIP file to your application, test it and iterate a few times to achieve optimal outcome;

Razor Optimizer Screen Shot
Razor Optimizer Screen Shot
A sample optimization report would look like this.


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 )
 
Comments (26)
test
1 Monday, 01 September 2008 05:17
tomonori nomura
test
Oh! good
2 Tuesday, 23 September 2008 06:05
javaoracle
I think razor is cool Deburgging tool for javascript developer.
i like this optimization in the web...
3 Thursday, 06 November 2008 21:23
manuel rodriguez
this is good another tecnologies is used in zkoss.org...with zul files...
Error listenerstart
4 Friday, 07 November 2008 01:01
wunc
I download RazorOptimizer-0.9.0.325.zip. And startup.bat

2008-11-7 13:37:38 org.apache.catalina.core.StandardContext listenerStart
严重: Error configuring application listener of class com.coachwei.razor.servlet.SessionListener
java.lang.ExceptionInInitializerError
at com.coachwei.razor.servlet.SessionListener.(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3618)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:894)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:857)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:475)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1102)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1020)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1012)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:683)
at org.apache.catalina.startup.Catalina.start(Catalina.java:537)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:271)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:409)
Caused by: java.lang.NullPointerException
at com.coachwei.razor.log.LogFactory.getMessage(Unknown Source)
at com.coachwei.razor.log.AbstractLog.getMessage(Unknown Source)
at com.coachwei.razor.log.AbstractLog.log(Unknown Source)
at com.coachwei.razor.log.AbstractLog.log(Unknown Source)
at com.coachwei.razor.log.LogFactory.loadResourceBundle(Unknown Source)
at com.coachwei.razor.log.LogFactory.init(Unknown Source)
at com.coachwei.razor.log.LogFactory.(Unknown Source)
... 31 more
2008-11-7 13:37:38 org.apache.catalina.core.StandardContext listenerStart
Very cool
5 Friday, 07 November 2008 01:34
Eugene Lazutkin
...and it is written using Dojo 1.1! Can't wait to try it out on some of my applications!
Re:Error listenerstart
6 Friday, 07 November 2008 08:42
Coach Wei
@wunc: looks like a bug!!!
What JVM version you are using?
Re:Re:Error listenerstart
7 Sunday, 09 November 2008 08:23
wunc
java version "1.5.0_15"
Re:Re:Re:Error listenerstart
8 Wednesday, 19 November 2008 00:16
Coach Wei
@wunc: see support forum:

http://www.razorspeed.com/phpBB3/viewtopic.php?f=5&t=8#p13
The Microsoft research project is called Deloto (not Denoto).
9 Monday, 01 December 2008 15:45
Stephen Lamm
http://research.microsoft.com/projects/doloto/
The Microsoft research project is called Doloto (not Denoto).
10 Monday, 01 December 2008 17:29
Stephen Lamm
http://research.microsoft.com/projects/doloto/
Re:The Microsoft research project is called Doloto (not Denoto).
11 Thursday, 04 December 2008 12:24
coach wei
Thanks Stephen!
Thansk
12 Friday, 22 January 2010 07:14
zidaan marshall
Thansk
13 Friday, 22 January 2010 07:17
zidaan marshall
Thansk
14 Friday, 22 January 2010 07:21
zidaan marshall
Thansk
15 Friday, 22 January 2010 07:51
zidaan marshall
replica watches
16 Wednesday, 03 March 2010 23:36
replica watches
That was her outlet when she was stressed about a test or needed to replica watches just clear replica watches her head, Kelly King said. Chelsea was born in Poway, a well-to-do suburb of homes and office parks northeast of San Diego. Her family, including her 13-year-old rolex Watches brother, followed rolex Watches Brent King to various mortgage banking jobs in the San Francisco Bay area and suburban Chicago before returning to the San Diego area. Their home was badly damaged in breitling Watches 2007 wildfires breitling Watches that ravaged Southern California. Brent, 47, is now between jobs. Kelly, 48, works as a medical assistant in a dermatologist's office. Chelsea researched 90 cartier Watches colleges, with cartier Watches an eye toward a career that would combine her interests in writing and environmental protection. She has been accepted by the University of Washington and the University of British omega Watches Columbia. She is omega Watches one of the most driven, personable, caring people that you could ever meet, Brent King said. Her goal in life is to brighten everyone's day. That's what she does, Panerai Watches and when she Panerai Watches walks into the room, you know she's there. She often stays up studying past midnight, working so hard that her parents urge her to ease off and spend more time with friends.
replica watches
17 Thursday, 04 March 2010 02:11
replica watches
The terrain is tricky out there, said Jan Caldwell, spokeswoman for the replica watches San Diego replica watches County Sheriff's Department. They're going slowly for the safety but also slowly to make sure they cover every single square inch. Authorities rolex watches also searched rolex watches Gardner's home in Lake Elsinore and his mother's home in San Diego, Caldwell said. She declined to comment on what, if any evidence, the searches produced. King's parents said breitling watches they last saw breitling watches Chelsea when she went to bed about 9:30 p.m. Wednesday after playing French horn in a school concert. On the way cartier watches home, they mailed cartier watches an application for financial aid at Boston University, one of 11 colleges where she applied. The parents heard Chelsea leave the house at 6:15 a.m. Thursday for a peer counseling omega watches commitment. But she omega watches wasn't home at 5:30 p.m., when Brent King returned from the gym and his wife got home with groceries. They described their daughter as a straight-A Panerai watches student and Panerai watches avid runner who plays French horn for the San Diego Youth Symphony. At suburban Poway High School, Chelsea runs on the cross-country team.
Vaio VGN-UX50
18 Friday, 05 March 2010 12:32
sd
Thanks. It sounds useful.
20 Sunday, 14 March 2010 19:20
Lucy
Thanks. It sounds useful. I will try to use Razor Optimizer and hope it will bring me a great many convenience.classifieds |ads|tempurpedic mattress
でも価格
21 Wednesday, 17 March 2010 21:14
でも価格
lxq
レプリカジャージ(7875円)、スウィングマンジャージ(13440円)リーボック ジャージ、オーセンティックジャージ(25800円~)と、同じジャージ同士でも価格の違いが、その素材や仕様に反映されていることがおわかりいただけたと思いますリーボック ジャージ
より丈夫で凝った造りの物を着るにこしたことはありませんが、その場合は価格にもその良さが表れてしまいますユニフォーム サイズ
また、値段の高いジャージは、多くの選手・種類を集めようとするコレクターの方向きではありませんユニフォーム サイズ
その一方で、バスケットボールや運動する時に着用する場合、それなりの耐久度や動きやすさ(生地が軽い・柔らかい)が求められますNBAジャージ

 本格的で丈夫なオーセンティックジャージを選ぶのか、数を集めたいからレプリカジャージを選ぶのか、その中間のスウィングマンジャージを選ぶのかは、お客様次第ですNBAジャージ
本文が、これまでご存知なかったお客様のご購入にあたっての何かしらの指標となれば幸いです。
レプリカユニフ
22 Wednesday, 17 March 2010 21:24
レプリカユニフ
lxq


レプリカジャージ(7875円)レプリカユニフォーム、スウィングマンジャージ(13440円)、オーセンティックジャージ(25800円~)と、同じジャージ同士でも価格の違いが、リーボック ジャージその素材や仕様に反映されていることがおわかりいただけたと思います。
より丈夫で凝った造りの物を着るにこしたことはありませんが、その場合は価格にもその良さが表れてしまいますNBAジャージ
また、値段の高いジャージは、多くの選手・種類を集めようとするコレクターの方向きではありません。
その一方で、バスケットボールや運動する時に着用する場合、それなりの耐久度や動きやすさ(生地が軽い・柔らかい)が求められます。

 本格的で丈夫なオーセンティックジャージNBAジャージを選ぶのか、数を集めたいからレプリカジャージを選ぶのか、その中間のスウィングマンジャージを選ぶのかは、お客様次第です。
本文が、これまでご存知なかったお客様のご購入にあたっての何かしらの指標となれば幸いですNBAジャージ
Paul Smith
23 Wednesday, 17 March 2010 22:22
Paul Smith
lxq
Paul Smith has an ability to anticipate trends and even trigger, not only in fashion but in the wider context of popular culture. Paul Smith manages to convey a genuine sense of fun and mischief mixed with his love of tradition and the classics. This is evident in the overall appearance of both Paul Smith Shoes,
Paul Smith Clothing.


If you like Cheap Paul Smith Shoes, but you do not love the normal price, then you need to spend some time searching online for a deal by Paul Smith Shoes. You may be able to find a dealer that offers a discount Paul Smith shoes on their stock of shoes to help you save money in this wonderfully elegant footwear. It may also be able to find an online Discount Paul Smith Shoes, which can be applied in the box to help you save even more money in her wonderful new partner Men Paul Smith Shoes.

プロモ
24 Thursday, 18 March 2010 10:02
プロモ
lcz
2006年に大々的にプロモーションされて衝撃的なデビューを果たしたAir Max360ですnike air max360。ソールと言える物はエアバッグのみで、一体化したケージが随所を補強して安定性を確保しています。エアは15psiに設定nike air max360、65もの層からエアバッグを形成し、これまで課題であった経年によるエア漏れを防止していますナイキ エアマックス 360。補強部位やエアバッグ内のピラーの形状、配置などをサイズやメンズとレディースで最適に変化させているようです。
販売店舗を限定するなど強気なセールスを見せていましたが、アウトレットでディスカウントされていましたair max 360 スニーカー
プロモ
25 Thursday, 18 March 2010 10:10
プロモ
lcz
2006年に大々的にプロモーションされて衝撃的なデビューを果たしたAir Max360ですエアマックス 360。ソールと言える物はエアバッグのみでエアマックス 360、一体化した課題であった経年によるエア漏れを防止していますnike air max360。補強部
プロモ
26 Thursday, 18 March 2010 10:21
プロモ
lcz
2006年に大々的にプロモーションされて衝撃的なairmax 360 デビュー安定性を確保していますnike airmax。エアは15psiに設定、65もの層エアマックス 2009をサイズやメンズと

Add your comment

Your name:
Your email:
Your website:
Subject:
Comment (you may use HTML tags here):