Minifying the Mapfish Client on Windows
Initially I was looking to download a ready-made “compiled” MapFish file, but was unable to find a version online. I have uploaded azipped version so if you want the file without going through the steps below you can download a copy. Note that if you have made any modifications to the MapFish files then these will not be available, and there are no guarantees it will work.
Step 1 - Install Python for Windows
First of all if Python is not installed on your system, then get the MSI installer from the Python site. I used version 2.5.4, so I’m not sure if the steps below work with later versions. Once it has been installed all .py extensions should be associated with the python interpreter. To check this you can run the following commands in a Windows command line prompt:
assoc.py ftype Python.File
Step 2 - Create a Virtual Python Environment
This step creates an isolated Python environment for JSTools. Using this “virtual” environment avoids using wrong script versions and references. The Mapfish instructions for Linux were as follows:
$ wget 'http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.3.2.tar.gz' $ tar xvzf virtualenv-1.3.2.tar.gz $ python virtualenv-1.3.2/virtualenv.py env $ source env/bin/activate
These rougly translate into Window’s speak as:
Download the VirtualEnv installer fromhttp://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.3.2.tar.gz (wget is simply a Linux program that handles the downloading of files).
Unzip the downloaded file (for example using 7-zip for Windows)
Run the following command in the Windows command prompt. Change the first parameter to point to the location of virtualenv.py you just downloaded, and the second to a folder where you want to create your virtual Python environment.
Step 3 - Install the JSTools
Again from the Windows command line, change your current directory to the newly created Scripts folder in your virtual environment setup.
Next run the following command (again from the Windows command line):
easy_install.exe -i http://dev.camptocamp.com/packages/mapfish/all/index JSTools
Trying to install the latest version of JSTools from http://github.com/whitmo/jstools/tarball/master caused errors (possibly due to Windows default download paths), but the rest of the steps worked fine with the JSTools available from the Mapfish (CamptoCamp) link used above.
Step 4 - Go Forth and Minify
[MapFish.js] root = D:/Tools/Mapfish/mapfish-client-1.2/mfbase/openlayers/lib D:/Tools/Mapfish/mapfish-client-1.2/mfbase/mapfish D:/Tools/Mapfish/mapfish-client-1.2/mfbase/geoext/lib first = OpenLayers/SingleFile.js OpenLayers.js ...rest of the file remains the same
jsbuild -o D:\Tools\Mapfish\ D:\Tools\Mapfish\mapfish-client-1.2\build\full.cfg
A new MapFish.js was created!
Step 5 - Test in Web Application
The previous reference to Mapfish could now be pointed to the newly created MapFish.js file:
Although the file is now ~1MB it is smaller than the individual files combined, and it requires less server requests which improves page loading times. Most web servers (including IIS and Apache, but not IIS running on Windows XP) allow gzip compression which will reduce this file to around 250KB.
If you encounter any problems or steps I’ve missed then please let me know!