[Chartjs]-Chart.js reduce file size

1👍

This might not be a complete answer, but your best bet is to download the unminified JS file from here or any other page which offer unminified releases.

Then, use a tool to remove parts which you don’t need. This can be quite tricky and was a trial-and-error job mostly, but:

This page has a nice tutorial about that with the Chrome Dev Console. Basically what the page says is that the Chrome Dev Console now (since Ver. 59) comes with the ability to capture coverage out-of-the-box. This means that you can interact with your Chart as long as you want and then look at which script part is never used and remove it in your favourite code editor.

After that, set up a JS minifier ( & uglifier) and in that way shrink it down a bit more.

With all that done, the JS package should now be (much) smaller, depending on how many features you’ve used from the library.

0👍

I had the same problem in my embedded project (service interface for our device). Solved using gzip compression. Full version of the file Chart.min.js (v3.6.0) reduced from 193 kB to 62 kB.

By removing unused parts (as mentioned before) the size could probably be further reduced by 20-30 % if I use only line chart, linear scale and time scale.

The compressed file is stored in the device and webserver is configured to send the field "Content-Encoding gzip" in http response header.

Leave a comment