Compress URL params with DEFLATE and a preset dictionary - #8
Merged
Merged
Conversation
base64+urlencoded JSON pushed template urls past 1kb. Url params and template payloads are now raw DEFLATE compressed with a preset dictionary and encoded as unpadded url-safe base64 (every character RFC 3986 unreserved, so urlencode never expands the token): _1<base64url> deflate with dictionary v1 (emitted) _0<base64url> deflate without dictionary (accepted) <base64> legacy standard base64 (accepted) The dictionary was built from 23k production template payloads and is a frozen byte-for-byte contract with the image service (image-service-lambda lib/url-codec.js) — md5 pinned in tests on both sides. Mean template token drops 444 -> 125 chars; the test-fixture template url drops 822 -> 251 chars. JSON is encoded with JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE before compression. Requires ext-zlib (declared in composer.json). The image service must deploy decode support (RingierIMU/image-service-lambda#515) before this ships. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
matthewnessworthy
enabled auto-merge (squash)
June 10, 2026 10:21
matthewnessworthy
disabled auto-merge
June 10, 2026 13:07
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
json_encode+base64_encode+urlencodepushed template URLs past 1kb, causing SEO issues. URL params and template payloads are now raw-DEFLATE compressed and encoded as unpadded URL-safe base64 (RFC 4648 §5) — every output character is RFC 3986 unreserved, sourlencode()never expands a token.New
UrlCodecwith a versioned token format:_1compress()emits_0b6b973310e98eb1286b280d1d65c45ea) was built from 23k real production template payloads: top payload shapes as contiguous skeletons, near-constant values (Now Hiring,de vânzare,SUPRAFAȚĂ, …), real bucket paths (horizon-files-prod/og-template/…,shared-folder-prod/…). It is a frozen byte-for-byte wire contract with the image service — never edit it; new vocabulary goes under prefix_2.JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODEbefore compression (kills\/doubling on S3 paths).ext-zlib/ext-jsondeclared in composer.json./-/segment) and their signatures are byte-identical to before.Results (real production corpus, n=2875)
The test-fixture template URL drops 822 → 251 chars; a real cde-prop payload tokenizes to 46 chars.
Tests
14 tests passing, including a pinned dictionary md5 (cross-language drift guard), roundtrips with unicode, legacy decode, and invalid-token rejection. Verified end-to-end against the lambda: PHP-signed URLs with
_1tokens pass signature validation and decode on both resize and template routes.Deploy order
🤖 Generated with Claude Code