Shipping ECharts compressed
Compressing ECharts takes 513 KB off every chart page and costs 31 ms on load. Commit 7d4f018 makes pack inline kit/echarts.js as deflate-raw and the page unpack it on load.
What changes
1 pack writes the deflated bytes into the script's data-deflate. A loader decodes them 2, inflates them 3 and runs the result 4. 5 charts.js mounts a chart once echartsReady has resolved.
--- skills/explainer/src/kit.ts
+ deflate: deflateRawSync(text.slice(header.length), { level: 9 }).toString("base64"),
--- skills/explainer/src/pack.ts
- `<script${type ? ` type="${type}"` : ""}>${safeScript(readKitText(path))}</script>`,
+ `<script${type ? ` type="${type}"` : ""}${deflate ? ` data-deflate="${deflate}"` : ""}>${safeScript(text)}</script>`,
--- skills/explainer/kit/unpack.ts (new)
+ const bytes = Uint8Array.from(atob(packed), (char) => char.charCodeAt(0));
+ const inflated = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
+ const script = document.createElement("script");
+ script.text = await new Response(inflated).text();
+ document.head.append(script);
+ window.echartsReady = unpack();
--- skills/explainer/kit/charts.ts
- if (!window.echarts) {
+ if (!(window.echarts || window.echartsReady)) {
+ window.echartsReady,
Alternatives
| Encoding | In the page | Baseline browsers decode it |
|---|---|---|
| deflate-raw in base64shipped: tied smallest | 418 KB | Yes |
| gzip in base64the same size as deflate-raw | 418 KB | Yes |
| Brotli in base64DecompressionStream does not read it | 344 KB | No |
| deflate-raw as Latin-1 textlarger once the page is UTF-8 | 470 KB | Yes |
The island bundle (60 to 300 KB) stays plain: it must run before the views and steps scripts, and unpacking it would delay them. CSS stays plain because it cannot wait for a script.
Older browsers
The deflate-raw format needs Chrome 103, Firefox 113 or Safari 16.4. On older browsers the unpack fails and logs the failure. The charts pack drew stay; the live ones that replace them never mount.
Approve shipping ECharts compressed?
Basis
Sizes are measured from kit/echarts.js by measure.ts; the timings are the ones the repository's AGENTS.md records.