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:
- Run the kompressor script (that's not compress.sh, but kompressor)
- You need to fix the compressed ButtonBase code
- (Optionally) you need to gzip you compressed code
- 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.
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.
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
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.