Skip to content

Repeated saves duplicate HTML content and increase file size #2237

Closed

Description

@banderlog

Saving folium.Map to HTML file via map.save('out.html') adds iteratively proportionally as many lines as many objects you have.

I.E. on a second map.save() will be added N strings, on third save will be added 2xN and so on.
N is number of objects + number of tiles + empty strings.
For 10 object it will be 32 strings.

It is a problem for maps with thousands of objects, when you can get +200KB for output file each time.

To Reproduce

import folium


mymap = folium.Map(location=[40.75, -73.98], zoom_start=13)

# 10 objects
locations = [
    [40.7829, -73.9654, "Central Park"],
    [40.7484, -73.9857, "Empire State Building"],
    [40.7580, -73.9855, "Times Square"],
    [40.7061, -73.9969, "Brooklyn Bridge"],
    [40.6892, -74.0445, "Statue of Liberty"],
    [40.7587, -73.9787, "Rockefeller Center"],
    [40.7128, -74.0060, "City Hall"],
    [40.7308, -73.9973, "Washington Square Park"],
    [40.7420, -74.0048, "The High Line"],
    [40.7118, -74.0131, "One World Trade Center"]
]

for lat, lon, name in locations:
    folium.Marker(
        location=[lat, lon],
        icon=folium.Icon(color="blue", icon="info-sign")
    ).add_to(mymap)

#  Save the as HTML file twice in a row
mymap.save("1.html")
mymap.save("2.html")
Output of `diff 1.html 2.html `
579a580,612
>     
>             tile_layer_052f99b21ed1f9bb1c251666826b3405.addTo(map_5c1c64a03c53392f2db23886f23f12a3);
>         
>     
>                 marker_63f8ecad580ed4635b59dcfaf6c3e61f.setIcon(icon_beb42bcc1ea445f94958395ebfe206ea);
>             
>     
>                 marker_b160f28fb6d129ef2f92cdf20ea3e4d6.setIcon(icon_e75ca799208df661741ebbf502942fca);
>             
>     
>                 marker_53b65bb222dd30de59a2e63245de6307.setIcon(icon_68748d7f297e38784cecd742f031d88b);
>             
>     
>                 marker_25b58c032f3524af0221ac1207168844.setIcon(icon_32131f76c1960e3d1549864864743cd2);
>             
>     
>                 marker_334210d9a39502bfdfed7afdbd9e79c3.setIcon(icon_79f631e614c35fa625cb9ebf66332aa3);
>             
>     
>                 marker_da7f6dc7f513fca1304a2326ea2f0816.setIcon(icon_cbf658a28b584b3cc19f9f6bb4e79bd2);
>             
>     
>                 marker_bf430c5d7c07635d674ed2a334bb8e75.setIcon(icon_2a596a031d157fecbc56bf8fb6cc6780);
>             
>     
>                 marker_bdd2c45a9c4ea0d913663870e08555da.setIcon(icon_b46c071e79f3899b2fb392d7bc213dab);
>             
>     
>                 marker_9dd46997657a85db4ffe1fd23d60ceb2.setIcon(icon_6defd56ba4021afd9de3f8e7297d13eb);
>             
>     
>                 marker_9623e338468155be7219352ee3f2ba7a.setIcon(icon_dd2bb17bb8228efb1570ab10408dc3a2);
>         

Expected behavior

No extra strings added

Environment (please complete the following information):

  • jupyter/cli both
  • Python version 3.12
  • folium version 0.20.0
  • branca version 0.8.2

Activity

  1. vraj2131 commented on Jun 12, 2026

    @vraj2131
    Contributor

    Hi, I’d like to work on this if it’s still available.

    I reproduced the issue locally on folium 0.20.0 / branca 0.8.2 with Python 3.12 (CLI). Saving the same folium.Map twice adds duplicate HTML on the second save — with 10 markers, diff 1.html 2.html shows ~32 extra lines, matching what you described.

    My plan is to trace Map.save() and the HTML rendering path to see why content is being appended instead of regenerated on each save, then add a test to ensure repeated saves produce identical output.

    Happy to open a PR once I’ve confirmed no one else is already working on it. Thanks!

  2. added a commit that references this issue on Jun 13, 2026
    2b7290a
  3. added a commit that references this issue on Jun 14, 2026
    f13798b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions