Commit 39a5890
perf(export): replace jszip with client-zip - 302 -> 211 kB bundle
The Download ZIP button bundles three short text files (the two Factorio
JSON documents plus the exchange string) for the headless CLI route. It
was costing 97 kB of the shipped bundle to do it.
`jszip`'s `browser` field resolves `./lib/index` to `dist/jszip.min.js`, a
97.6 kB pre-minified **browserify** bundle. That is an opaque IIFE with its
own module registry, so it cannot be tree-shaken, and the pako 1.0.11 baked
inside it cannot dedupe against the app's pako 3.0.1. The app was shipping
two pako majors plus `readable-stream`, `setimmediate` and eight more Node
shims in order to write three text files.
Measured, by building both ways:
| | raw | gzip |
| --- | --- | --- |
| before (jszip) | 302.07 kB | 99.81 kB |
| after (client-zip) | 211.44 kB | 73.11 kB |
| delta | **-90.63 kB (-30%)** | **-26.70 kB (-27%)** |
Isolating the libraries: a build with the zip feature stubbed out entirely
is 204.95 kB, so `client-zip` costs **6.49 kB** where `jszip` cost 97.1 kB
- about 15x smaller for this use.
Confirmed gone from the bundle rather than assumed: `JSZip`, `jszip`,
`setImmediate`, `readable-stream` and `_tr_stored_block` markers all drop
to zero, and pako's `incorrect header check` string goes from 2 occurrences
to 1 - the codec's pako 3.0.1 remains, the duplicate is gone. `vp build`
still prints no warnings at all, which is the standing invariant.
**The output is materially unchanged, and the reason is worth recording:
jszip was not compressing either.** Both writers emit `Stored` entries at
0% - `generateAsync` without an explicit `compression` option does not
deflate. So the whole pako 1.x payload was dead weight for this path. The
downloaded archive goes 7888 -> 7936 bytes (+48 bytes, +0.6%), which is the
central-directory layout differing slightly, not a compression regression.
`jszip` moves to devDependencies and stays the **reader** in
`test/zipExport.spec.ts`. That is deliberate: checking a client-zip archive
with client-zip would prove self-consistency, not correctness. Validated
against a third implementation too - `unzip -t` (Info-ZIP) reports "No
errors detected" and lists all three entries with correct names, sizes and
CRCs.
Note `pnpm add -D` will not relocate a package whose installed version
already satisfies the range - it prints "Already up to date" and leaves it
where it was - so the dependencies -> devDependencies move was made by
editing `package.json` directly and re-running `pnpm install`.
The spec gains two cases, because changing the *writer* means entry
presence is no longer a sufficient assertion: one parses both JSON entries
back and checks real fields, and asserts the exchange string survives
verbatim against the fixture; one covers preset-name-derived entry naming
and the exact entry set. 1249 -> 1251 tests.
Not adopted for currency: `client-zip`'s last human commit is 2025-03-14
(the newer repo push is a Dependabot branch). This swap buys bundle size
and API fit, not fresher maintenance. What it does improve is backlog - 8
open issues against jszip's 412 and 40 unanswered PRs.
Gate: `pnpm run verify` exit 0 - 314 files formatted, 301 clean, app 1251
passed / 3 skipped, worker 12, container 3.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GjMSePtN9aTgr8EtZp66k11 parent 605a4cc commit 39a5890
4 files changed
Lines changed: 92 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
10 | 32 | | |
11 | 33 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
17 | 48 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
11 | 18 | | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
24 | 60 | | |
0 commit comments