I am porting a webmap built with HTML/CSS/Leaflet to a GeoDjango/Leaflet framework, and want to know the fastest way to display map layers. For the HTML/CSS/Leaflet map, my layers are hosted as flat GeoJSON files and called using L.GeoJSON(). The layers display very fast.

For the GeoDjango framework, however, the layers display much more slowly. I use almost identical code, but am guessing the geom data has to be serialized to GeoJSON, which is responsible for the slow display. Is there any way to speed up this process? What would be the fastest way to get layers to display using a GeoDjango framework?

GeoDjango code to display layer:

From urls.py:

from django.conf.urls import include, url
from models import mbls
from djgeojson.views import GeoJSONLayerView

    urlpatterns = [
        url(r'^mbls/', GeoJSONLayerView.as_view(model=mbls), name='mbls'),

From index.html:

var mblInt = new L.GeoJSON(null, {
                style: { color: '#000000',

    $.getJSON('{% url "mbls" %}', function (data) {

... other code ...

var map = L.map("map", {
            zoom: 11,
            center: [35.435, -106.54], 
            minZoom: 6,
            maxZoom: 20,
            layers: [basemap, mblInt]

1 Answer 1


You might not be comparing apples with apples here. The two approaches are fundamentally different, one case is static the other one dynamic.

In one case, you have a static geojson file that the browser loads and then displays. This is fast because the data is fixed and does not change. So the browser can just download that file and render, and on reload this file is already in the browser cache and will render even faster.

In the second case, you are loading dynamic data from the database. This is likely to be slower as you say, because Django will get the data from the database, convert it to geojson and then return it. The advantage of this is that as the data changes in the database, your map will automatically update.

So you are essentially comparing a complex page with dynamic data with a static html page.

If your data does not change, then loading the data from the database is not necessary. Also, you could cache your database driven page using a cache backend such as memcached. This would probably make your page load as fast as with the file based approach.

  • That makes sense. I guess my question is more what sort of speed-ups are there for the dynamic framework that I've listed out in my question? Would the cache backend be the best option for that? Can you suggest some resources on that?
    – jbukoski
    Feb 14, 2017 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.