-
Notifications
You must be signed in to change notification settings - Fork 25.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): support custom srcset attributes in NgOptimizedImage (#…
…47082) This commit adds a `rawSrcset` attribute as a replacement for the `srcset` attribute. The `srcset` attribute cannot be set statically on the image directive because it would cause images to start downloading before the "loading" attribute could be set to "lazy". Changing the name to `rawSrcset` allows the directive to control the timing of image loading. It also makes it possible to support custom loaders for `srcset` file names. Rather than having to repeat the image origin for each image, the existing `rawSrc` value and image loader can be composed to generate each full URL string. The developer must only provide the necessary widths for the `srcset`. For example, the developer might write: ```markup <img rawSrc="hermes.jpg" rawSrcset="100w, 200w" ... /> ``` with a loader like: ```js const loader = (config) => `path/${config.src}?w=${config.width}`; ``` and the img tag will ultimately be set up as something like: ```markup <img src="path/hermes.jpg?w=100" srcset="path/hermes.jpg?w=100 100w, path/hermes.jpg?w=200 200w" .../> ``` PR Close #47082
- Loading branch information
Showing
5 changed files
with
341 additions
and
28 deletions.
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
Oops, something went wrong.