Skip to content
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

plotly.min.js bloats binary size #176

Closed
kaihowl opened this issue Jan 7, 2024 · 2 comments · Fixed by #231
Closed

plotly.min.js bloats binary size #176

kaihowl opened this issue Jan 7, 2024 · 2 comments · Fixed by #231

Comments

@kaihowl
Copy link
Contributor

kaihowl commented Jan 7, 2024

Templates like this one include plotly.min.js such that static plots can be output correctly. For binaries using plotly that only output plots using the CDN distributed version of plotly, this unnecessarily increases the binary size.

Would it make sense to add a Cargo feature that allows to skip the inclusion of the minified plotly version (~2.5 MB)? For example plotly-vendoredjs with a default of true that can be set to false?

Or is there already a way to accomplish the desired behavior of not unnecessarily including the minified plotly version into the __TEXT,__const section of the binary?

@sharkdp
Copy link

sharkdp commented Aug 9, 2024

I also ran into this while working on plotly.rs-based plotting support for Numbat (sharkdp/numbat#464).

I looked a little bit into how askama (the templating engine used by plotly.rs) works. I couldn't anything that would allow us to have a sort of compile-time switch like a Rust feature gate. Something like

      {% cfg(feature = "plotly-js-vendored") -%}  <!-- this does not exist, AFAIS -->
        {% if remote_plotly_js -%} <!-- the runtime switch that is already present -->
        <script src="https://cdn.plot.ly/plotly-2.12.1.min.js"></script>
        {% else -%}
        <script type="text/javascript">{% include "plotly.min.js" %}</script>
        {% endif -%}
      {% else %}
        <script src="https://cdn.plot.ly/plotly-2.12.1.min.js"></script>
      {% endcfg %}

So I guess the only way to do this would be to duplicate https://github.com/plotly/plotly.rs/blob/main/plotly/templates/plot.html into a new plot-cdn.html (or similar) that would come without the embedded variant. Using feature gates in the Rust code, we could then select one or the other template.

Or does someone see a way to solve this using askama?

@andrei-ng
Copy link
Collaborator

Hi @sharkdp , TBH I don't know if it is possible via askama either. I will look as well.

I agree with your proposal as well. If you have already the code for that, please submit a PR and we can merge it until we find an alternative way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants