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

Optimize images as part of production builds #10391

Merged
merged 12 commits into from
Jun 5, 2024
Merged

Conversation

parlough
Copy link
Member

@parlough parlough commented Apr 9, 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 a few images, I saw lighthouse perf score increases from 5-15 points.

Closes #6487
Closes #9527 as this plugin also validates alt is always specified

@flutter-website-bot
Copy link
Collaborator

flutter-website-bot commented Apr 9, 2024

Visit the preview URL for this PR (updated for commit 77bd8a6):

https://flutter-docs-prod--pr10391-feat-optimize-images-9kqzqpc9.web.app

@sfshaza2
Copy link
Contributor

Parker, can we either land this or close? I really hate stinky PRs that hang around for weeks and weeks.

@parlough
Copy link
Member Author

@sfshaza2 Yep, sorry! I was waiting for the dart.dev equivalent to land to work out the kinks there first. It landed today with dart-lang/site-www@bcbff3e.

I'll work on getting this updated and ready for review sometime this week.

@parlough parlough changed the title [WIP] Optimize images as part of production builds Optimize images as part of production builds May 31, 2024
@parlough parlough marked this pull request as ready for review May 31, 2024 23:50
@parlough parlough merged commit 551ffcc into main Jun 5, 2024
9 checks passed
@parlough parlough deleted the feat/optimize-images branch June 5, 2024 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add alt text Improve image format/sizing and caching
4 participants