[OpenLayers-Users] slimming OL

Christopher Schmidt crschmidt at metacarta.com
Tue Mar 9 09:57:38 EST 2010


On Tue, Mar 09, 2010 at 08:15:49AM -0600, P Kishor wrote:
> From Firebug's 'Net' panel, my mixed, OpenLayers, Google Maps test page shows --
> 
> Google js
> ----------
> maps: 4.3 KB
> main.js: 67.7 KB
> vp: 661 B
> %7Bmod_drag,mod_ctrapi%7D.js: 11.2 KB
> vp: 660 B
> =============
> That totals 85 KB
> 
> OpenLayers.js: 695.1 KB
> 
> Why is OL almost 10 times the size of Gmaps scripts?

Why aren't you compressing your Javascript when you serve it?

> If I want the functionality somewhat equivalent to what Gmaps
> provides, can I re-build OL with fewer parts so it slims down?

Did you read http://docs.openlayers.org/library/deploying.html ?

> Right now OL is the largest js component of my work, more than Gmaps
> and jQuery combined. Partly, it seems that there are many frameworks
> layered on top of each other. OL depends on Prototype and other
> frameworks, 

OpenLayers does not depend on Prototype. It did at one point, but 
all components of OpenLayers which depended on Prototype were changed
to be part of the OpenLayers library, and all extraneous pieces
removed. While it is true that OpenLayers depends in part on pieces
which could be available through another external library, these
pieces are not a majority of the code.

The default 'lite' build of OpenLayers is 125k. This incldues 23
different files, including layer types, reprojection support, and
map navigation.

When you compress that output with gzip, it drops to just 32k.

This includes all of the "framework" pieces you've mentioned; 
meaning that overall, these pieces form much less than 20% of any
OpenLayers build (since the majority of the code in the base build
is not the framework components, but the Map itself).

> so even if I were using Prototype (I am not, but this is
> just for illustration), I would still get Prototype within OL,
> duplicating stuff.

Most likely, duplicating less than 10kb of code total. If you were
in for trimming every byte, this might matter, but currently it looks
like you're serving uncompressed Javascript, so you can't be looking
to trim every byte quite yet :)

> This is one of the reasons I don't even want to look at GeoExt, and
> MapFish and other frameworks made from OpenLayers, instead trying to
> accomplish my goals with just OL. From MapFish's notes, it is
> "composed of the ExtJS, OpenLayers, GeoExt JavaScript toolkits." So
> MapFish uses ExtJS and GeoExt and OL, and GeoExt uses ExtJS and OL,
> and OL uses Prototype and Rico, and Rico uses Prototype. This is very
> circular and confusing.

I don't see how that's circular or confusing. Perhaps if your last step
said "OL uses ExtJS and Rico" that might be the case.

Note that:
 1. There is no dependancy in the core of OpenLayers on Rico
 2. Any of the Rico code we have is self-contained, and does not depend
    in any way on Prototype.
 3. Again, OpenLayers doesn't actually use Prototype. It uses a small
    subset of the Prototype library, carved out specifically to solve
    the problems that OpenLayers needs to.

Overall, GeoExt is much smaller than OpenLayers; Overall, much more of
what GeoExt is trying to do is available from the underlying ExtJS libraries.
(A compressed full build of GeoExt is only 20kb; less than 1/5th of a 
'full' OpenLayers build, which no one should be using anyway.)

OpenLayers is a complex library implementing hundreds of features for 
interacting with dozens of map types. When compressed, even the full version,
with all Controls, Layers, etc. is approximately 128kb. A more typical
build clocks in near half that, excluding unused controls, layers, etc.

ExtJS is a complex library implementing hundreds of features for creating
compelling interactive web applications. When compressed, even the full
version, with all the bells and whistles, is 111kb.

GeoExt is an extension of ExtJS specifically to add support for OpenLayers,
creating it easier to create compelling interactive web mapping applications.
When compressed, the full set of GeoExt code is 28kb.

MapFish is a toolkit for creating complete web applications -- including
the server side and client side. On the client side, MapFish is almost 
entirely GeoExt, with some extensions to support the MapFish server better,
as I understand it. This adds capabilties to OpenLayers + GeoExt like
Search, better styling, offline editing, etc. MapFish is a much more
reasonable comparison to GeoDjango than it is to GeoExt.

In total, an appropriately configured build of OL, Ext, and GeoExt probably
totals up to about 100kb compressed; probably closer to 400kb uncompressed.
However, the quantity of features available in that amount of javascript
is gigantic compared to the Google Maps Javascript, which provides the 
ability to... drag a map around. If you just wanted that, you can get
it from OpenLayers in 100kb uncompressed, 40kb compressed.

If you want to build a web application, you're going to want more than
OpenLayers. If you're not willing to pay the price of a few tiles worth
of bandwidth to get it, it's likely going to be your loss in the end.

Best Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list