Version 2 (modified by sderle, 7 years ago)

stylistic changes

Build Profiles

OpenLayers Build Profiles are a way to control which code classes are included in a single file build of OpenLayers.

Development Version

When developing with OpenLayers, typically users will use the lib/OpenLayers.js file, which will append script tags to the DOM for each OpenLayers class. This method works fine for development, but due to network latency, is slow. Additionally, the content of these files is not compressed, so network transfer time is slower than it might be otherwise.

Creating a Single File

In order to avoid the optimize the end-user's experience, the OpenLayers distribution includes tools which allow you to build your own single file version of the code. This code uses a configuration file to choose which files should be included in the build: In this way, for production use, you can remove classes from your OpenLayers JavaScript library file which are not used in your application.

In addition, the OpenLayers build scripts strip unneccesary comments and whitespace to save space, using the jsmin library.

To build a single file version of OpenLayers, cd into the build directory of the OpenLayers release under a UNIX-like shell with access to Python. Type ./build.sh profilename.

OpenLayers ships with two configurations to create a single file version:

  • library: This file includes all of the OpenLayers code, other than code which is still in development at the time of a release.
  • lite: This file includes a small subset of OpenLayers code, designed to be integrated into another application. It includes only the Layer types neccesary to create tiled or untiled WMS, and does not include any Controls. This is the result of what was at the time called "Webmap.js" at the FOSS4G Web Mapping BOF.

Creating your own Profile

Profiles are simple to create. You can start by copying library.cfg or lite.cfg to something else, e.g. myversion.cfg in the build directory, and then build it with the following command:

  $ ./build.sh myversion

The beginning of the file should include pieces which need to be included before anything else. In the case of the default OpenLayers build, this is:

 OpenLayers/SingleFile.js
 OpenLayers.js
 OpenLayers/BaseTypes.js
 OpenLayers/Util.js

If you wish to create a build where you must specify each file you wish to include, you should then add files to an '[include]' stanza, as lite.cfg does. If you wish to create a build where all files in the lib/ directory are included by default, and you wish to *exclude* certain files, you can do this by putting filenames under the [exclude] header. Look at the files library.cfg and lite.cfg in the build/ directory for examples of this behavior.

For example, if you wished to remove the OverviewMap control from the default OpenLayers build, you would create a copy of library.cfg, and add the lines:

    [exclude] 
    OpenLayers/Control/OverviewMap.js

If, instead, you wished to add the MouseDefaults and PanZoom controls to the lite configuration, you could add the following to the lite.cfg:

    [include]
    OpenLayers/Control.js
    OpenLayers/Control/MouseDefaults.js
    OpenLayers/Control/PanZoom.js