-
Notifications
You must be signed in to change notification settings - Fork 5.2k
perf: Homepage image optimization #15677
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
Open
wackerow
wants to merge
13
commits into
dev
Choose a base branch
from
homepage-images
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
01bb7fc
assets: update image assets
wackerow cfbcf7d
assets: portrait versions, homepage section banners
wackerow d5e861c
feat: implement HomepageSectionImage
wackerow 96805c8
performance: drop home hero quality to 20
wackerow e0e3de2
refactor: home hero source and srcset
wackerow dbee423
refactor: use classNames over style props
wackerow 2b3c5e9
fix: props, types
wackerow 3748fe1
fix: HomeHero story
wackerow a77377a
fix: image height full
wackerow 9341a01
Merge branch 'dev' into homepage-images
wackerow bd19195
fix: import path
wackerow 2bafe42
Merge branch 'dev' into homepage-images
wackerow 366d811
Merge branch 'dev' into homepage-images
wackerow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export { default as ContentHero, type ContentHeroProps } from "./ContentHero" | ||
export { default as HomeHero, type HomeHeroProps } from "./HomeHero" | ||
export { default as HomeHero } from "./HomeHero" | ||
export { default as HubHero } from "./HubHero" | ||
export { default as MdxHero, type MdxHeroProps } from "./MdxHero" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import type { StaticImageData } from "next/image" | ||
import { getImageProps } from "next/image" | ||
|
||
import { breakpointAsNumber } from "@/lib/utils/screen" | ||
|
||
// Import all landscape images (all PNG now) | ||
import developersHubHero from "@/public/images/heroes/developers-hub-hero.png" | ||
// Import all portrait images (all PNG) | ||
import developersHubHeroPortrait from "@/public/images/heroes/developers-hub-hero-portrait.png" | ||
import layerTwoHubHero from "@/public/images/heroes/layer-2-hub-hero.png" | ||
import layerTwoHubHeroPortrait from "@/public/images/heroes/layer-2-hub-hero-portrait.png" | ||
import learnHubHero from "@/public/images/heroes/learn-hub-hero.png" | ||
import learnHubHeroPortrait from "@/public/images/heroes/learn-hub-hero-portrait.png" | ||
import quizzesHubHero from "@/public/images/heroes/quizzes-hub-hero.png" | ||
import quizzesHubHeroPortrait from "@/public/images/heroes/quizzes-hub-hero-portrait.png" | ||
|
||
const imageMap: Record< | ||
string, | ||
{ | ||
mobile: StaticImageData | ||
desktop: StaticImageData | ||
} | ||
> = { | ||
activity: { | ||
mobile: layerTwoHubHero, | ||
desktop: layerTwoHubHeroPortrait, | ||
}, | ||
learn: { | ||
mobile: learnHubHero, | ||
desktop: learnHubHeroPortrait, | ||
}, | ||
builders: { | ||
mobile: developersHubHero, | ||
desktop: developersHubHeroPortrait, | ||
}, | ||
community: { | ||
mobile: quizzesHubHero, | ||
desktop: quizzesHubHeroPortrait, | ||
}, | ||
} | ||
|
||
type HomepageSectionImageProps = { | ||
sectionId: string // e.g. "activity", "learn", "builders", "community" | ||
alt: string | ||
className?: string | ||
} | ||
|
||
export default function HomepageSectionImage({ | ||
sectionId, | ||
alt, | ||
className, | ||
}: HomepageSectionImageProps) { | ||
const images = imageMap[sectionId] | ||
|
||
if (!images) { | ||
throw new Error( | ||
`Image not found for section: ${sectionId}. Available sections: ${Object.keys(imageMap).join(", ")}` | ||
) | ||
} | ||
|
||
const common = { | ||
alt, | ||
// Be very specific: Desktop max 512px, Mobile 100vw | ||
sizes: `(max-width: ${breakpointAsNumber.md}px) 100vw, 512px`, | ||
priority: false, | ||
} | ||
|
||
const { | ||
props: { srcSet: desktop }, | ||
} = getImageProps({ | ||
...common, | ||
...images.desktop, | ||
quality: 25, | ||
}) | ||
|
||
const { | ||
props: { srcSet: mobile, ...rest }, | ||
} = getImageProps({ | ||
...common, | ||
...images.mobile, | ||
quality: 40, | ||
}) | ||
|
||
return ( | ||
<picture className={className}> | ||
<source | ||
media={`(min-width: ${breakpointAsNumber.md}px)`} | ||
srcSet={desktop} | ||
/> | ||
<source | ||
media={`(max-width: ${breakpointAsNumber.md - 1}px)`} | ||
srcSet={mobile} | ||
/> | ||
<img {...rest} alt={alt} className="h-auto w-full object-cover" /> | ||
</picture> | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.