forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add experimental image post-processing (vercel#15875)
This PR adds a second experimental post-processing step for the framework introduced by @prateekbh in vercel#14746. The image post-processing step scans the rendered document for the first few images and uses a simple heuristic to determine if the images should be automatically preloaded. Analysis of quite a few production Next apps has shown that a lot of sites are taking a substantial hit to their [LCP](https://web.dev/lcp/) score because an image that's part of the "hero" element on the page is not preloaded and is getting downloaded with lower priority than the JavaScript bundles. This post-processor should automatically fix that for a lot of sites, without causing any real performance effects in cases where it fails to identify the hero image. This feature is behind an experimental flag, and will be subject to quite a bit of experimentation and tweaking before it's ready to be made a default setting.
- Loading branch information
Showing
14 changed files
with
278 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 @@ | ||
module.exports = { target: 'serverless', experimental: { optimizeFonts: true } } |
This file contains 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,4 @@ | ||
module.exports = { | ||
target: 'serverless', | ||
experimental: { optimizeImages: true }, | ||
} |
This file contains 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,24 @@ | ||
import React from 'react' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<link rel="preload" href="already-preloaded.jpg" /> | ||
<img src="already-preloaded.jpg" /> | ||
<img src="tiny-image.jpg" width="20" height="20" /> | ||
<img src="hidden-image-1.jpg" hidden /> | ||
<div hidden> | ||
<img src="hidden-image-2.jpg" /> | ||
</div> | ||
<img src="main-image-1.jpg" /> | ||
<div> | ||
<img src="main-image-2.jpg" /> | ||
</div> | ||
<img src="main-image-3.jpg" /> | ||
<img src="main-image-4.jpg" /> | ||
<img src="main-image-5.jpg" /> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains 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,29 @@ | ||
function Home({ stars }) { | ||
return ( | ||
<div className="container"> | ||
<main> | ||
<div> | ||
<link rel="preload" href="already-preloaded.jpg" /> | ||
<img src="already-preloaded.jpg" /> | ||
<img src="tiny-image.jpg" width="20" height="20" /> | ||
<img src="hidden-image-1.jpg" hidden /> | ||
<div hidden> | ||
<img src="hidden-image-2.jpg" /> | ||
</div> | ||
<img src="main-image-1.jpg" /> | ||
<img src="main-image-2.jpg" /> | ||
<img src="main-image-3.jpg" /> | ||
<img src="main-image-4.jpg" /> | ||
<img src="main-image-5.jpg" /> | ||
</div> | ||
<div>Next stars: {stars}</div> | ||
</main> | ||
</div> | ||
) | ||
} | ||
|
||
Home.getInitialProps = async () => { | ||
return { stars: Math.random() * 1000 } | ||
} | ||
|
||
export default Home |
This file contains 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,18 @@ | ||
import React from 'react' | ||
import Head from 'next/head' | ||
|
||
const Page = () => { | ||
return ( | ||
<> | ||
<Head> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Modak" | ||
rel="stylesheet" | ||
/> | ||
</Head> | ||
<div>Hi!</div> | ||
</> | ||
) | ||
} | ||
|
||
export default Page |
Oops, something went wrong.