August 30, 2008

Increase Mapguide Enterprise/Open Performance with Javascript Compression using the YUI Compressor

Filed under: Mapguide — Tags: , — Darrin Maidlow @ 7:18 am

Javascript compression is something I had on my list for the next major release of RADE.  RADE is not quite ready for this step yet, so I thought I would give it a shot on Mapguide Enterprise and see what kind of results it would yield.  For a small site or an internal site this will probably not yield significant benefits.  However if you run a large public site javascript compression could squeeze out some more performance as well as save you on bandwidth costs.  Yahoo has a good article on .

I did some brief looking around and word on the internets is that the is one of the better compressors out there.  The YUI compressor is an open source java applet.   This *should* work with Mapguide Open, heck this might even be done already in MGOS – but I am only using Enterprise so I cannot confirm, deny, or test this.  

Some of the key things the compressor will do:

  1. remove all comments
  2. remove all white space and line breaks
  3. rename all local variables and parameters to single characters

The YUI compressor should not alter variable values or your logic in any way.

To use the YUI compressor you will need to .  Note that if you have the Oracle client installed, you probably have Java already  Once you have Java, you can download a copy of the (I’m going to start referring to it as the YC now…).  If you don’t feel like downloading Java and the YC – I’ve attached the processed files at the bottom of this post.

Lets first look at the javascript shipped with Mapguide Enterprise.  If you browse to your web server extension viewer files (the default location is C:\Program Files\Autodesk\MapGuideEnterprise2009\WebServerExtensions\www\viewerfiles I believe) you will see ten javascript files.  If you choose to process these files on your own please back them up first.  Don’t blame me if you don’t backup your files and something goes wrong =).

Before YC:

Mapgude Enterprise Javascript before YUI Compression

Using the YC is simple:

   1: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\browserdetect.js browserdetect.js

 

Update the paths to Java and the YC as per your environment.  Using the handy dir /B *.js > go.bat I created a batch file of all the javascript files in the viewerfiles folder.  Be sure to run this from a dos window in the viewerfiles folder, or update the paths.  You will also need to create the comp folder in viewerfiles.   Quick cut and pasting created the following batch file:

   1: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\browserdetect.js browserdetect.js
   2: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\contextmenu.js contextmenu.js
   3: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\digitize.js digitize.js
   4: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\hashtable.js hashtable.js
   5: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\initdwfctrl.js initdwfctrl.js
   6: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\legend.js legend.js
   7: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\numfmt.js numfmt.js
   8: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\pngfix_map.js pngfix_map.js
   9: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\sarissa.js sarissa.js
  10: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\wz_jsgraphics.js wz_jsgraphics.js

 

(*Sorry about the overlap.  I’m working on a new layout and am addressing that in there)

Running that output all of the compressed of the files down somewhat, to pretty significantly.

Mapgude Enterprise Javascript After YUI Compression

A quick comparison of one of the function calls:

   1: function MenuData(menuName, arrowHeight, scrollInc, scrollDelay, minSize, iconScrollUp, iconScrollUpDisabled, iconScrollDown, iconScrollDownDisabled, owner, withIFrame, bkColor)
   2: function MenuData(F,H,I,K,E,G,D,J,A,C,B,L)

 

As you can see – the savings can be significant.

I’m not using the yet so I did not process those files, but I did check some of the JS in there and each script file had a huge header comment.  It looks like Fusion could also benefit from some compression action.  Please note, I’ve been running my web tier using this script for a day or two.  I’ve not run any serious testing on this code – so try this at your own risk.  You did make that backup I suggested, right?  That said, I have not personally experienced any problems yet.  Also, should you compress your viewerfiles and have problems be sure to try your backups.  Especially before calling your dealer or Autodesk for help. (sorry product support and ADN guys.  Please don’t hate me =] ).

if you would rather not run the YC yourself.

Enjoy!

1 Comment »

  1. Awesome read , I’m going to spend more time researching this subject

    Comment by 1930 great depression facts — September 21, 2011 @ 12:54 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress

Switch to our mobile site