Skip to content

Commit

Permalink
Themes: Lazy load screenshots (#96961)
Browse files Browse the repository at this point in the history
Defers the loading of the theme screenshots in the theme showcase until the user scrolls near them with a `loading='lazy'` attribute, effectively decreasing the initial data load from 35MB to 2.5MB (-92%).
  • Loading branch information
mmtr authored Dec 4, 2024
1 parent 5867a8e commit ec77614
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/components/theme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export class Theme extends Component {

return (
<img
loading="lazy"
alt={ isScreenshotLoaded ? decodeEntities( description ) : '' }
className="theme__img"
src={ themeImgSrc }
Expand Down
1 change: 1 addition & 0 deletions client/components/theme/test/__snapshots__/index.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`Theme rendering should match snapshot 1`] = `
<img
alt=""
class="theme__img"
loading="lazy"
src="https://i0.wp.com/s0.wp.com/wp-content/themes/pub/twentyseventeen/screenshot.png?fit=479%2C360"
srcset="https://i0.wp.com/s0.wp.com/wp-content/themes/pub/twentyseventeen/screenshot.png?fit=479%2C360&zoom=2 2x"
/>
Expand Down

0 comments on commit ec77614

Please sign in to comment.