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

feat(next/image): preload priority images #20615

Merged
merged 4 commits into from
Dec 30, 2020

Conversation

Timer
Copy link
Member

@Timer Timer commented Dec 30, 2020

The HTML Living Standard explicitly says href should be omitted to prevent the loading of an incorrectly sized image:
https://html.spec.whatwg.org/multipage/semantics.html#attr-link-imagesrcset

image

Since it's in the spec, I assume this is valid-enough HTML.

This also dedupes preloads which the old implementation did not.


Fixes #18756
x-ref #19118
Fixes #18720

@Timer Timer requested a review from styfle December 30, 2020 19:59
@vercel vercel bot temporarily deployed to Preview December 30, 2020 19:59 Inactive
@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:44 Inactive
@ijjk
Copy link
Member

ijjk commented Dec 30, 2020

Stats from current PR

Default Server Mode (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary Timer/next.js feat/preload-priority Change
buildDuration 9.9s 10.1s ⚠️ +162ms
nodeModulesSize 83 MB 83 MB ⚠️ +2.22 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary Timer/next.js feat/preload-priority Change
/ failed reqs 0 0
/ total time (seconds) 2.031 2.023 -0.01
/ avg req/sec 1231.07 1236.07 +5
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.228 1.282 ⚠️ +0.05
/error-in-render avg req/sec 2036.43 1950.04 ⚠️ -86.39
Client Bundles (main, webpack, commons)
vercel/next.js canary Timer/next.js feat/preload-priority Change
677f882d2ed8..769b.js gzip 12.8 kB 12.8 kB
framework.HASH.js gzip 39 kB 39 kB
main-a6ce971..96b9.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
Overall change 59.1 kB 59.1 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary Timer/next.js feat/preload-priority Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary Timer/next.js feat/preload-priority Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-1a1f628..eeb5.js gzip 1.61 kB 1.61 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.05 kB 8.05 kB
Client Build Manifests
vercel/next.js canary Timer/next.js feat/preload-priority Change
_buildManifest.js gzip 322 B 322 B
Overall change 322 B 322 B
Rendered Page Sizes
vercel/next.js canary Timer/next.js feat/preload-priority Change
index.html gzip 616 B 616 B
link.html gzip 621 B 621 B
withRouter.html gzip 609 B 609 B
Overall change 1.85 kB 1.85 kB

Serverless Mode
General Overall increase ⚠️
vercel/next.js canary Timer/next.js feat/preload-priority Change
buildDuration 12.3s 12.1s -179ms
nodeModulesSize 83 MB 83 MB ⚠️ +2.22 kB
Client Bundles (main, webpack, commons)
vercel/next.js canary Timer/next.js feat/preload-priority Change
677f882d2ed8..769b.js gzip 12.8 kB 12.8 kB
framework.HASH.js gzip 39 kB 39 kB
main-a6ce971..96b9.js gzip 6.59 kB 6.59 kB
webpack-7193..1446.js gzip 751 B 751 B
Overall change 59.1 kB 59.1 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary Timer/next.js feat/preload-priority Change
polyfills-67..b7d1.js gzip 31.2 kB 31.2 kB
Overall change 31.2 kB 31.2 kB
Client Pages
vercel/next.js canary Timer/next.js feat/preload-priority Change
_app-6220e08..9a40.js gzip 1.28 kB 1.28 kB
_error-4b0b5..2c91.js gzip 3.44 kB 3.44 kB
hooks-5f309a..7282.js gzip 887 B 887 B
index-57f580..c562.js gzip 227 B 227 B
link-1a1f628..eeb5.js gzip 1.61 kB 1.61 kB
routerDirect..bd82.js gzip 303 B 303 B
withRouter-2..e384.js gzip 302 B 302 B
Overall change 8.05 kB 8.05 kB
Client Build Manifests
vercel/next.js canary Timer/next.js feat/preload-priority Change
_buildManifest.js gzip 322 B 322 B
Overall change 322 B 322 B
Serverless bundles
vercel/next.js canary Timer/next.js feat/preload-priority Change
_error.js 1 MB 1 MB
404.html 2.67 kB 2.67 kB
hooks.html 1.92 kB 1.92 kB
index.js 1 MB 1 MB
link.js 1.06 MB 1.06 MB
routerDirect.js 1.05 MB 1.05 MB
withRouter.js 1.05 MB 1.05 MB
Overall change 5.17 MB 5.17 MB
Commit: eab6af4

> **Attention**: This property is only meant for advanced usage. Switching an
> image to load with `eager` will normally **hurt performance**.
>
> You are probably looking for the [`priority`](#priority) property instead,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> You are probably looking for the [`priority`](#priority) property instead,
> We recommend using the [`priority`](#priority) property instead,

@kodiakhq kodiakhq bot merged commit 45b87aa into vercel:canary Dec 30, 2020
@@ -147,7 +153,7 @@ When `eager`, load the image immediately.

### unoptimized

When true, the source image will be served as-is instead of changing quality, size, or format. Defaults to false.
When true, the source image will be served as-is instead of changing quality, size, or format. Defaults to `false`.
Copy link
Member

@styfle styfle Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to change the default here to be highlighted, also change for the other sections too. For example, priority.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Timer Timer deleted the feat/preload-priority branch December 30, 2020 21:11
@@ -257,7 +255,8 @@ describe('Image Component Tests', () => {
browser = null
})
runTests()
it('should NOT add a preload tag for a priority image', async () => {
// FIXME: this test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whats the problem here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client-side transitions will inject a preload tag. One could argue this is desirable behavior if the image has priority.

<Head>
<link
key={
'__nimg-' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'__nimg-' +
'__next_image_' +

Do we have a convention here?

Copy link
Member Author

@Timer Timer Dec 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No convention, was just trying to something short to avoid a collision. The user shouldn't really ever see this. Our sometimes convention is _n_------------ though.

></Image>
<Image
loading="eager"
id="basic-image"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Timer Did you intend to have two images with id="basic-image"?

@vercel vercel locked as resolved and limited conversation to collaborators Jan 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v 10 - low Largest Content Painting score with new Image next/image priority preloads the largest size
3 participants