Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up automatic image optimization pipeline #5779

Merged
merged 7 commits into from
May 29, 2024
Merged

Set up automatic image optimization pipeline #5779

merged 7 commits into from
May 29, 2024

Conversation

parlough
Copy link
Member

@parlough parlough commented May 7, 2024

Use 11ty's first-party image transformation plugin to automatically optimize images, convert them to png, webp, and avif, and then transform the site HTML to use the <picture> element to select the best one for the user. This only runs in production deploy builds to reduce serving time. Also applies lazy loading and async decoding to all images, even when serving without optimizations. The transform also adds a hash of the image, allowing us to expand caching for images in Firebase hosting.

To account for the transformed HTML structure, some minor HTML and CSS changes were needed as well.

Overall, this reduces page load time on pages that use images, and reduces unnecessary downloads that were due to a relatively short cache time for images. On a page with just a few images, such as https://dart.dev/tools/pub/automated-publishing, the lighthouse perf score increases around 10-15 points.

Fixes #4473
Fixes #3124

@parlough parlough added the review.tech Awaiting Technical Review label May 7, 2024
@dart-github-bot
Copy link
Collaborator

dart-github-bot commented May 7, 2024

Visit the preview URL for this PR (updated for commit 7aca287):

https://dart-dev--pr5779-feat-image-opt-vhu98xo4.web.app

@parlough parlough marked this pull request as ready for review May 7, 2024 19:05
@atsansone
Copy link
Contributor

@parlough : I see no reason not to make this change, but I'm not seeing any benefit. Both the staged version and live version of https://dart.dev/web/debugging and https://dart.dev/tools/pub/automated-publishing, Lighthouse scores were 97 for all.

Current
image

Staged
image

@parlough
Copy link
Member Author

parlough commented May 20, 2024

@atsansone You'll see increased improvements for a mobile report or with a lot more images. Another benefit of this change is the much improved caching, as the plugin adds hashes to the image URLs, allowing us to extend the cache time of images greatly.

As another metric for those pages without any caching benefits, visiting the automated publishing page with simulated slow 3g, dropped load time from 28s->21s.

@parlough parlough requested a review from atsansone May 20, 2024 13:19
@parlough parlough changed the title Setup automatic image optimization pipeline Set up automatic image optimization pipeline May 20, 2024
@atsansone atsansone assigned parlough and unassigned atsansone May 29, 2024
@atsansone atsansone added st.RFM.% Ready to Merge but has suggestions and removed review.tech Awaiting Technical Review labels May 29, 2024
@parlough parlough removed the st.RFM.% Ready to Merge but has suggestions label May 29, 2024
@parlough parlough removed their assignment May 29, 2024
@parlough parlough merged commit bcbff3e into main May 29, 2024
10 checks passed
@parlough parlough deleted the feat/image-opt branch May 29, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants