-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated HTML could be much smaller #975
Comments
You're right that the generated HTML/JS could be more efficient. Right now it is necessary for everything to render into one HTML file, so they can be embedded in Jupyter notebooks.
|
Consider this generated code, which adds a circle with a popup to a layer:
So i have two questions:
I think there definetely should be a reason we do all this, instead of simply chaining Leaflet instructions like this, for example (this code displays exactly the same circle and popup):
Thanks. |
I've been looking around to find something to contribute, and this seemed like an interesting issue (and something I definitely thought of before when using Folium!)
I can confirm ~30% size reduction from minifying JS alone (I used |
@Norrius that sounds like a good plan. There are many whitespaces to trim too. |
I think @DenisFLASH is right about the default parameters but I wonder if a good minimiser will eliminate the common expressions anyway? |
Generating shorter code in the first place (@DenisFLASH) will of course help a lot, but I don't know enough about Leaflet.js to do it and having compressed JS should be beneficial in any case. I tried out a couple of available minifiers:
var html_abc = $(`<div id="html_abc" style="width: 100.0%; height: 100.0%;"><i>Mt. Hood Meadows</i></div>`)[0];
popup_def.setContent(html_abc); It also has a mangler, which (in theory) could have helped with long names as well (it renames things into
All of these only apply simple transformations such as removing whitespace, so no clever replacements (as suggested by @mpickering). I also want to check if django-compressor would work here. Unlike the rest, it is not a drop-in compressor function, so it needs some more investigation. |
Hi @Norrius, thanks for taking on this project! Having smaller htmls is a good goal so I’ll be happy to review any PRs related to this. As I see it there are three things we need to decide on:
Other ideas in this thread are interesting as well, thanks for bringing them up @DenisFLASH. But as @mpickering said a good JS processor might already solve some of these. I’ll list the other ideas here, so someone can open another issue or PR for them if still relevant after the JS compression project.
|
While we're on the topic, I was expecting that the |
@mpickering is this issue resolved? |
The HTML generated by folium is quite verbose which leads to big files when you have 2000 markers for example.
I'm sure there are more savings but these two seemed like the most obvious.
The text was updated successfully, but these errors were encountered: