Feature Request: first request WebP, second request: AVIF
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- aws, typescript
Research direction
Start by locating the TypeScript AWS Lambda entry point that handles image requests and the CloudFront response and caching configuration. Trace how the current AVIF conversion and If-None-Match handling work. Done means the first request can return WebP promptly, the follow-up can produce AVIF, and the documented Cache-Control behavior is covered by tests or verification.
Written by the indexing model from the issue text.
Description
Background
Lamada takes long time to transform image to avif format.
Solution: Stale-While-Revalidate
stale-while-revalidate is a caching setting. It’s a parameter in the Cache-Control header, and it tells CDNs how long they can keep serving the image after it expires:
Cache-Control: max-age=3600, stale-while-revalidate=60
↑ how long a file can be cached for
↑ how long a CDN can keep serving
the file after max-age expires
Here’s how we used it to make sure AVIF never makes image responses slow:
- First Request: WebP
On the first request, we serve the image as WebP, not as AVIF.
We also set the Cache-Control header to max-age=0, stale-while-revalidate=31536000
-
Immediate Expiry
Because max-age is set to 0, the WebP image expires immediately. This prompts the CDN to forward the second request to us. -
Second Request: AVIF
When the second request arrives, we serve the image as AVIF.
Responding to the second request can take several seconds because AVIF conversion is slow. But thanks to stale-while-revalidate, our CDN (CloudFront) keeps serving the WebP image until the conversion is complete.
We recognize the second request from the first by the If-None-Match header. Only the second request has it.
When the AVIF image is ready, we return it with Cache-Control: max-age=31536000. This allows the CDN to cache and serve it for a long time.
- Dominant language
- TypeScript
- Stars
- 276
- Forks
- 151
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aws-samples/image-optimization
-
CDK CLI and aws-cdk-lib version mismatch leads to deployment errorsMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
bug wontfix
Difficulty 4/5 3-5 days Newbie friendliness 35/100
aws-samples/image-optimization#65 · 1 comment ·
-
[Feature request] Supply original image from original S3 bucketMay be free again @achrafsouk claimed this 427 days ago, and no pull request is open. Open
aws-samples/image-optimization#47 · 1 comment · 1 assignee ·
-
Difficulty 4/5 3-5 days Newbie friendliness 28/100
aws-samples/image-optimization#33 · 11 comments ·
All issues in aws-samples/image-optimization
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Comfy-Org/ComfyUI_frontend#20346 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
decentralized-identity/didwebvh-ts#203 ·
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
lingdojo/kana-dojo#31791 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Telegram webhook: line breaks lost since switch to rich messagesPossibly taken @Kshot3000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
github_actions security
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day