Skip to end of metadata
Go to start of metadata

It is possible to compress Mapbuilder releases even further then the /bin/ script. In the trunk there are two files: /kompressor and /lib/util/custom_rhino.jar. The first is a simpel shell script to collect a series of javascript files and compress them to one big compressed file. The latter is based on dojo's shrinksafe compressor.

The big benefit, other then the compression, is the combination of multiple files in one file. The HTTP initialisation time is often longer then the actual transport of data and as such it is faster to download one big file then multiple small files.

There are a few tricks to get it going, right now it is a bit of a rough ride, which should be eased out in the future, but this will help you going:

  1. You need to get a list of all the required javascript files and turn it into a kompressor script
  2. You need to make sure that any XSL-generated javascript keeps running
  3. Run the kompressor script (that's not, but kompressor)
  4. You need to make sure that the compressed mapbuilder library does not load any other javascript files
  5. You need to fix the compressed ButtonBase code
  6. (Optionally) you need to gzip you compressed code
  7. You need to change the index.html to point to the new compressed mapbuilder library

Might sound complicated, but it really is not.

Step 1 get the required files.

The easy way is to use LiveHTTPHeaders in firefox to get all the javascript files which you particular mapbuilder application uses. The hard way is to figure it out yourself.
Next you need to turn it into a kompressor script, each javascript file should result in a line like this

Starting with java -jar lib/util/custom_rhino.jar -c then the relative path of your javascript file and then ending with >> lib/MapbuilderCompressed.js 2>&1

Step 2a XSL generated JS

As far as I know this only happens in GmlRendererWZ.js, so if you do not use it, you can skip this step and go to step 2b.
Search for eval(js) The javascript in there uses objRef, whereas the compressor has turned objRef into a variable like _4. Probably the easiest way is to replace all references to objRef in GmlRendererWZ.xsl by <xsl:value-of: "$objRef"/> And add a parameter objRef to GMLRendererWZ.xsl. Also in GmlRendererWZ.js you need to add

just before

This approach should be applied to any other script that generates javascript through xsl.
Run the kompressor script in shell.
Once the script has finished, search in MapbuilderCompressed.js for "objRef" and replace it by the variable which is in the beginning of the line (probably _4)
Continue with step 3.

Step 2b Run the kompressor

In a shell do sh kompressor, this might take a while.

Step 3 prevent other js files from loading.

Mapbuilder has one loadscript function, at the moment the easiest way is to block that function in your compressed mapbuilder library. Open MapbuilderCompressed.js in your favourite text editor and search for: document.createElement("script"); the lines below it determine what script should be loaded. But since all scripts are already loaded we can change this to:

Which basically states that the script is loaded.

This however does not stop IE from complaining that it is not loaded, so to fix that one you can search for

and add

in the while loop (after readyState=="loaded")

Step 4 Fix ButtonBase

ButtonBase is slightly odd once compressed, which results in not showing disabled images. Search for function ButtonBase then you have to locate the statement:

Only in compressed form. The compressed form changes disabledImage to a variable like _4. You need to change that back to the above code. A bit further down that snippet there is another two references to disabledImage which need to be replaced as well. They look like this, in this case it is _4, but it can be different in your case:

Step 5 GZip your code.

Since most servers and browsers can serve gzipped files and unzip them on the fly, it is a good idea to use gzip. This can decrease your already compressed file with another 60%. Just run gzip /lib/MapbuilderCompressed.js and you end up with /lib/MapbuilderCompressed.js.gz

Step 6 Modify index.html

This is very easy, just replace


(or MapbuilderCompressed.js when you choose not to use gzip).
This is all folks, if you have any comments, please let me know on the mapbuilder-dev list.

  • No labels