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

Add support for preloading responsive images #55

Open
goodguyry opened this issue Oct 30, 2023 · 0 comments
Open

Add support for preloading responsive images #55

goodguyry opened this issue Oct 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@goodguyry
Copy link
Member

Description

<link rel="preload"> now supports responsive image resource hints.

https://web.dev/preload-responsive-images/

We should add support for declaring imagesrcset and imagesizes attributes when preloading responsive images.

Example based on the article's example:

am_preload(
	[
		'handle'      => 'preload-wolf',
		'src'         => 'wolf.jpg',
		'version'     => '1.0.0',
		'as'          => 'image'
		'mime_type'   => 'image/jpeg',
		'imagesrcset' => 'wolf_400px.jpg 400w, wolf_800px.jpg 800w, wolf_1600px.jpg 1600w',
		'imagesizes'  =>'50vw',
	]
);

Alternatively, we may find declaring imagesrcset as an array beneficial:

am_preload(
	[
		'handle'      => 'preload-wolf',
		'src'         => 'wolf.jpg',
		'version'     => '1.0.0',
		'as'          => 'image'
		'mime_type'   => 'image/jpeg',
		'imagesrcset' => [
			400  => 'wolf_400px.jpg',
			800  => 'wolf_800px.jpg',
			1600 => 'wolf_1600px.jpg',
		],
		'imagesizes'  =>'50vw',
	]
);

Use Case

The linked article has a few examples of use-cases. One we recently ran up against is preloading a hero image to reduce LCP.

@goodguyry goodguyry added the enhancement New feature or request label Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant