-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat: unflag responsive images #13917
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6e3d6e5
feat: unflag responsive images
ascorbic 6534434
Merge branch 'main' into stable-images
ascorbic 153fa25
Update option names
ascorbic f4289f5
Add changeset for `priority`
ascorbic ca44d6c
Changes from review
ascorbic 1aac15b
Changes from review
ascorbic 5a4cd3c
Apply suggestions from code review
ascorbic a11540a
Changes from review
ascorbic d4b5275
Fix fixture
ascorbic 61c7cb4
Merge branch 'main' into stable-images
ascorbic 339e071
Update packages/astro/src/types/public/config.ts
ascorbic 520eeb9
Update changeset
ascorbic d88b6b9
Apply suggestions from code review
ascorbic 87a96f6
Merge branch 'main' into stable-images
ascorbic 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| 'astro': minor | ||
| --- | ||
|
|
||
| Adds a new `priority` attribute for Astro's image components. | ||
|
|
||
| This change introduces a new `priority` option for the `<Image />` and `<Picture />` components, which automatically sets the `loading`, `decoding`, and `fetchpriority` attributes to their optimal values for above-the-fold images which should be loaded immediately. | ||
|
|
||
| It is a boolean prop, and you can use the shorthand syntax by simply adding `priority` as a prop to the `<Image />` or `<Picture />` component. When set, it will apply the following attributes: | ||
|
|
||
| - `loading="eager"` | ||
| - `decoding="sync"` | ||
| - `fetchpriority="high"` | ||
|
|
||
| The individual attributes can still be set manually if you need to customize your images further. | ||
|
|
||
| By default, the Astro [`<Image />` component](https://docs.astro.build/en/guides/images/#display-optimized-images-with-the-image--component) generates `<img>` tags that lazy-load their content by setting `loading="lazy"` and `decoding="async"`. This improves performance by deferring the loading of images that are not immediately visible in the viewport, and gives the best scores in performance audits like Lighthouse. | ||
|
|
||
| The new `priority` attribute will override those defaults and automatically add the best settings for your high-priority assets. | ||
|
|
||
| This option was previously available for experimental responsive images, but now it is a standard feature for all images. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```astro | ||
| <Image | ||
| src="/path/to/image.jpg" | ||
| alt="An example image" | ||
| priority | ||
| /> | ||
| ``` | ||
|
|
||
| > [!Note] | ||
| > You should only use the `priority` option for images that are critical to the initial rendering of the page, and ideally only one image per page. This is often an image identified as the [LCP element](https://web.dev/articles/lcp) when running Lighthouse tests. Using it for too many images will lead to performance issues, as it forces the browser to load those images immediately, potentially blocking the rendering of other content. | ||
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,91 @@ | ||
| --- | ||
| 'astro': minor | ||
| '@astrojs/vercel': patch | ||
| --- | ||
|
|
||
| The responsive images feature introduced behind a flag in [v5.0.0](https://github.com/withastro/astro/blob/main/packages/astro/CHANGELOG.md#500) is no longer experimental and is available for general use. | ||
|
|
||
| The new responsive images feature in Astro automatically generates optimized images for different screen sizes and resolutions, and applies the correct attributes to ensure that images are displayed correctly on all devices. | ||
|
|
||
| Enable the `image.responsiveStyles` option in your Astro config. Then, set a `layout` attribute on any <Image /> or <Picture /> component, or configure a default `image.layout`, for instantly responsive images with automatically generated `srcset` and `sizes` attributes based on the image's dimensions and the layout type. | ||
|
|
||
| Displaying images correctly on the web can be challenging, and is one of the most common performance issues seen in sites. This new feature simplifies the most challenging part of the process: serving your site visitor an image optimized for their viewing experience, and for your website's performance. | ||
|
|
||
| For full details, see the updated [Image guide](https://docs.astro.build/en/guides/images/#responsive-image-behavior). | ||
|
|
||
| ## Migration from Experimental Responsive Images | ||
|
|
||
| The `experimental.responsiveImages` flag has been removed, and all experimental image configuration options have been renamed to their final names. | ||
|
|
||
| If you were using the experimental responsive images feature, you'll need to update your configuration: | ||
|
|
||
| ### Remove the experimental flag | ||
|
|
||
| ```diff | ||
| export default defineConfig({ | ||
| experimental: { | ||
| - responsiveImages: true, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Update image configuration options | ||
|
|
||
| During the experimental phase, default styles were applied automatically to responsive images. Now, you need to explicitly set the `responsiveStyles` option to `true` if you want these styles applied. | ||
|
|
||
| ```diff | ||
| export default defineConfig({ | ||
| image: { | ||
| + responsiveStyles: true, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| The experimental image configuration options have been renamed: | ||
|
|
||
| **Before:** | ||
| ```js | ||
| export default defineConfig({ | ||
| image: { | ||
| experimentalLayout: 'constrained', | ||
| experimentalObjectFit: 'cover', | ||
| experimentalObjectPosition: 'center', | ||
| experimentalBreakpoints: [640, 750, 828, 1080, 1280], | ||
| experimentalDefaultStyles: true, | ||
| }, | ||
| experimental: { | ||
| responsiveImages: true, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| **After:** | ||
| ```js | ||
| export default defineConfig({ | ||
| image: { | ||
| layout: 'constrained', | ||
| objectFit: 'cover', | ||
| objectPosition: 'center', | ||
| breakpoints: [640, 750, 828, 1080, 1280], | ||
| responsiveStyles: true, // This is now *false* by default | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Component usage remains the same | ||
|
|
||
| The `layout`, `fit`, and `position` props on `<Image>` and `<Picture>` components work exactly the same as before: | ||
|
|
||
| ```astro | ||
| <Image | ||
| src={myImage} | ||
| alt="A responsive image" | ||
| layout="constrained" | ||
| fit="cover" | ||
| position="center" | ||
| /> | ||
| ``` | ||
|
|
||
| If you weren't using the experimental responsive images feature, no changes are required. | ||
ascorbic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Please see the [Image guide](https://docs.astro.build/en/guides/images/#responsive-image-behavior) for more information on using responsive images in Astro. | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent note!