Repository navigation
feat(build): add --compress flag to write gzip copies of generated assets - #389
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the optional compression step requested in #345.
cook build web --compresswalks the generated site and writes a gzip-compressed sibling (page.html.gz) next to every text asset — HTML, CSS, JS, JSON, XML, SVG and.cooksources — so static hosts that support precompressed assets (notably GitLab Pages) serve them directly. Details:flate2(level 9), which was already compiled into the binary transitively throughreqwest/self_update— effectively no new dependency. Brotli was considered and left out for now..gzis only kept when it is actually smaller than the original, and existing.gzfiles are never re-compressed on repeated builds...., N files compressed.Fixes #345
Testing
Three new integration tests in
tests/build.rs(written first, confirmed red):--compressproduces.gzsiblings forindex.html, the CSS bundle and the search index, which decompress byte-identical to the originals, and no image gets a.gz.gzfiles--compresstwice produces no.gz.gzartifactscargo fmt,cargo clippy, and the fullcargo testsuite pass cleanly.