-
Notifications
You must be signed in to change notification settings - Fork 9
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
Feat: use pre-loaded WebP background image on homepage #2523
Conversation
compressed the JPEG versions into WebP with quality set to 50%.
Here's a summary of the improvements I tried and the measurement I did of changes in performance (i.e. "benchmarking"). The improvements on #2490 that made sense to try were:
This one didn't seem applicable because we're not using an ResultsI measured the performance of the homepage before any improvements and then after each improvement by generating Lighthouse reports in Google Chrome devtools against my locally running Benefits app. There are four scenarios:
I did two rounds of testing these scenarios, and for each scenario, I recorded 5 samples. My Lighthouse settings:
Round 1 results1. JPEG images, no preload
2. JPEG images, with preload
3. WebP images, no preload
4. WebP images, with preload
In Round 1, using WebP images increased the Performance score slightly and decreased the time for Largest Contentful Paint (LCP). An interesting result is that using preload with either JPEG or WebP images increased the time for First Contentful Paint (FCP). Round 2 results1. JPEG images, no preload
2. JPEG images, with preload
3. WebP images, no preload
4. WebP images, with preload
Results for Round 2 are relatively similar to those of Round 1. Round 2 shows a clearer difference in performance. In Round 2, using WebP images increased the Performance score and decreased the time for LCP. Similar to results from Round 1, preloading either JPEG or WebP images increased the time for FCP. Raw reportsThe Lighthouse reports I generated are attached here as JSON files: ConclusionThese results show that preloading WebP images overall reduces the amount of time to load the page than what we were doing (not preloading and using JPEG images). Regarding the FCP time increase, I don't think there is anything more we can do to how the background image loads to improve it. The FCP time may improve when we do other web performance improvements like optimizing how we're loading CSS and Javascript (#2493) and enabling text compression for our server responses. The improvements in this PR alone are not enough to get us down to an LCP of 2.5 seconds or less (what Google's Core Web Vitals initiative defines as a good user experience), but they at least do provide about a 0.4 - 0.5 second improvement under the simulated slow 4G throttling that Lighthouse uses. Other helpful reading |
ideally, the user's browser supports WebP and will show the image, but just in case it doesn't, we want the white text to be readable. use the same color as the left side of the background image. this contrast ratio passes WCAG AAA requirements.
Another good section to read: https://web.dev/articles/preload-scanner#css_background_images |
this is just to be more consistent with other usages in our codebase and doesn't change anything functionally.
I'll go ahead and merge #2524 into this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice 👍
Thanks for the detailed comments and the great execution @angela-tran! 🎊 💯 💨 |
Closes #2490
This PR switches out our JPEG background image to a WebP image. It also adds HTML that will trigger preloading of the appropriate image based on media queries.
Lastly, to handle the case where the user's browser does not support WebP, we will set the background-color of the page to have sufficient contrast with the text on the page. (PR #2524)
See #2523 (comment) for details on the observed performance gains.