-
Notifications
You must be signed in to change notification settings - Fork 241
PreloadHeroImage should use imagesrcset attribute not srcset #823
Copy link
Copy link
Closed
Description
I just noticed that the PreloadHeroImage transformer is adding a preload link with a srcset attribute when it should rather be adding imagesrcset per https://web.dev/preload-responsive-images/
amp-toolbox/packages/optimizer/lib/transformers/PreloadHeroImage.js
Lines 62 to 81 in 4b59cdc
| const preload = createElement('link', { | |
| 'rel': 'preload', | |
| 'href': heroImage.src, | |
| 'as': 'image', | |
| 'data-hero': '', | |
| }); | |
| if (heroImage.media) { | |
| preload.attribs.media = heroImage.media; | |
| } | |
| if (heroImage.srcset) { | |
| try { | |
| parseSrcSet(heroImage.srcset); | |
| preload.attribs.srcset = heroImage.srcset; | |
| } catch (err) { | |
| this.log.warn( | |
| `Invalid srcset '${heroImage.srcset}' for amp-img src '${heroImage.src}'`, | |
| err.message | |
| ); | |
| } | |
| } |
Also, should not an imagesizes attribute be added to the link if the img has sizes attribute?
Lastly, it seems that the Validator hasn't been updated to allow srcset (or imagesrcset) or sizes (or imagesizes) on the link element:
Doesn't the transformer currently thus create invalid AMP?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels