fix(PPT-764): Prefer AVIF over WebP in format auto-selection#5
Open
adityaverm-a wants to merge 1 commit into
Open
fix(PPT-764): Prefer AVIF over WebP in format auto-selection#5adityaverm-a wants to merge 1 commit into
adityaverm-a wants to merge 1 commit into
Conversation
Reorder FORMAT_PRIORITY to avif > webp in both the container auto-optimizer and the CloudFront dit-header-normalization function so clients advertising image/avif receive AVIF instead of always falling back to WebP. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes automatic image format selection so that AVIF is preferred over WebP when a client supports both, keeping CloudFront header normalization and the container auto-optimizer in sync.
Changes:
- Reordered
FORMAT_PRIORITYto preferavifoverwebpin both the container auto-optimizer and the CloudFrontdit-header-normalizationfunction. - Updated/added unit tests to assert AVIF is chosen when both AVIF and WebP are accepted.
- Updated the infrastructure snapshot to reflect the CloudFront Function code change.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| source/container/src/services/transformation-resolver/auto-optimization/auto-optimizer.ts | Changes container-side FORMAT_PRIORITY so auto format selection picks AVIF before WebP. |
| source/container/src/services/transformation-resolver/auto-optimization/auto-optimizer.test.ts | Updates/adds unit tests to validate AVIF preference in auto-selection. |
| source/constructs/lib/v8/functions/dit-header-normalization.js | Changes edge-side FORMAT_PRIORITY so Accept normalization selects AVIF first. |
| source/constructs/lib/v8/test/unit/dit-function.test.ts | Updates unit test expectation for AVIF vs WebP selection from Accept. |
| source/constructs/lib/v8/test/snapshot/snapshots/image-processing-stack.test.ts.snap | Updates snapshot to match the new CloudFront Function priority ordering. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+8
to
9
| const FORMAT_PRIORITY = ['avif', 'webp', 'jpeg', 'png', 'heif', 'tiff', 'raw', 'gif']; | ||
| // TODO, DISCUSS WITH TEAM FOR OPTIMAL FORMAT PRIORITIY LIST |
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
FORMAT_PRIORITYfromwebp > aviftoavif > webpin the container auto-optimizer and the CloudFrontdit-header-normalizationfunctionAccept: image/avif,image/webp,..., DIT now selects AVIF instead of always falling back to WebPRoot cause
FORMAT_PRIORITYranked WebP above AVIF in two places:source/container/.../auto-optimizer.ts— container format auto-selectionsource/constructs/lib/v8/functions/dit-header-normalization.js— CF Function collapsesAccept→ singledit-acceptheaderIf only the container changed, production would still serve WebP because the CF Function strips
image/avifbefore the request reaches the container.Test plan
auto-optimizer.test.ts— avif preferred when both avif+webp accepteddit-function.test.ts— Acceptimage/avif,image/webp,image/png→dit-accept: image/avif?format=avif&quality=80→ valid AVIF output (547 B from test.png)dit-accept: image/avif,image/webp→ AVIF (547 B), not WebP (370 B)curl -H "Accept: image/avif,image/webp,image/*" <dit-url>returns AVIFDeploy note
Both the CloudFront Function and the container image must ship together. Deploying only one layer leaves AVIF broken.
Known follow-up
Sharp reports AVIF output as
Content-Type: image/heif; Chrome may download instead of inline-render when hitting the URL directly. File bytes are valid AVIF. Consider mappingheif→avifin response headers as a separate fix.Made with Cursor