* Add subresource integrity information & scripts * Include the integrity hashes in all tutorials also * Change wording of one of the build scripts
3.8 KiB
layout | title | bodyclass |
---|---|---|
v2 | Download | download-page |
Download Leaflet
Version | Description |
---|---|
Leaflet 1.0.3 | Stable version, released on January 23, 2017. |
Leaflet 1.1-dev | In-progress version, developed on the master branch. |
Leaflet 0.7.7 | Legacy version, released on November 18, 2013 and last updated on October 26, 2015. |
Note that the master version can contain incompatible changes, so please read the changelog carefully when upgrading to it.
Using a Hosted Version of Leaflet
The latest stable Leaflet release is hosted on a CDN — to start using
it straight away, place this in the head
of your HTML code:
<link rel="stylesheet" href="https://unpkg.com/leaflet@{{ site.latest_leaflet_version}}/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@{{ site.latest_leaflet_version}}/dist/leaflet.js"></script>
To avoid potential security problems, we recommend and encourage enabling subresource integrity when using Leaflet from a CDN:
<link rel="stylesheet" href="https://unpkg.com/leaflet@{{ site.latest_leaflet_version}}/dist/leaflet.css"
integrity="{{site.integrity_hash_css}}"
crossorigin=""/>
<script src="https://unpkg.com/leaflet@{{ site.latest_leaflet_version}}/dist/leaflet.js"
integrity="{{site.integrity_hash_uglified}}"
crossorigin=""></script>
Using a Downloaded Version of Leaflet
Inside the archives downloaded from the above links, you will see four things:
leaflet.js
- This is the minified Leaflet JavaScript code.leaflet-src.js
- This is the readable, unminified Leaflet JavaScript, which is sometimes helpful for debugging. (The integrity hash for this file is {{site.integrity_hash_source}})leaflet.css
- This is the stylesheet for Leaflet.images
- This is a folder that contains images referenced byleaflet.css
. It must be in the same directory asleaflet.css
.
Unzip the downloaded archive to your website's directory and add this to the head
of your HTML code:
<link rel="stylesheet" href="/path/to/leaflet.css" />
<script src="/path/to/leaflet.js"></script>
Using a JavaScript package manager
If you use the npm
package manager, you can fetch a local copy of Leaflet by running:
npm install leaflet
You will find a copy of the Leaflet release files in node_modules/leaflet/dist
.
Leaflet Source Code
These download packages above only contain the library itself. If you want to download the full source code, including unit tests, files for debugging, build scripts, etc., you can download it from the GitHub repository.
Building Leaflet from the Source
Leaflet build system is powered by the Node.js platform, which installs easily and works well across all major platforms. Here are the steps to set it up:
- Download and install Node
- Run the following commands in the command line:
npm install -g jake
npm install
Now that you have everything installed, run jake build
inside the Leaflet directory.
This will combine and compress the Leaflet source files, saving the build to the dist
folder.