Skip to content

feat(build): add --compress flag to write gzip copies of generated assets - #389

Merged
dubadub merged 1 commit into
mainfrom
feat/build-compress
Aug 6, 2026
Merged

dubadub merged 1 commit into
mainfrom
feat/build-compress

Conversation

@dubadub

@dubadub dubadub commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

Implements the optional compression step requested in #345.

cook build web --compress walks the generated site and writes a gzip-compressed sibling (page.html.gz) next to every text asset — HTML, CSS, JS, JSON, XML, SVG and .cook sources — so static hosts that support precompressed assets (notably GitLab Pages) serve them directly. Details:

  • Opt-in via the flag: hosts like Netlify/CDNs compress on the fly, so the extra files are only written when asked for.
  • gzip only via flate2 (level 9), which was already compiled into the binary transitively through reqwest/self_update — effectively no new dependency. Brotli was considered and left out for now.
  • Images/fonts are skipped (already compressed), a .gz is only kept when it is actually smaller than the original, and existing .gz files are never re-compressed on repeated builds.
  • The build summary reports the count: ..., N files compressed.

Fixes #345

Testing

Three new integration tests in tests/build.rs (written first, confirmed red):

  • --compress produces .gz siblings for index.html, the CSS bundle and the search index, which decompress byte-identical to the originals, and no image gets a .gz
  • default build writes no .gz files
  • running --compress twice produces no .gz.gz artifacts

cargo fmt, cargo clippy, and the full cargo test suite pass cleanly.

…sets

Writes a <file>.gz sibling for every generated HTML, CSS, JS, JSON,
XML, SVG and .cook file so static hosts that serve precompressed
assets (e.g. GitLab Pages) can use them directly. Images and other
already-compressed formats are skipped, and a .gz is only kept when
it is smaller than the original. Uses flate2, which was already in
the dependency tree via reqwest/self_update.

Fixes #345
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 this pull request may close these issues.

Compress static site generated files

1 participant