plotly.min.js bloats binary size
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?
I also ran into this while working on plotly.rs-based plotting support for Numbat (https://github.com/sharkdp/numbat/pull/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?
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.