amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Add native `img` to the AMP validator

Open rbeckthomas opened this issue 6 years ago • 15 comments

Add native img tag to the AMP Validator

This issue falls under the umbrella of changes which are a part of the 'amp-img deprecation': #30442.

We will be adding the native img tag to the validator which will allow for native img tags which require the following attributes...

Standard image:

  • alt
  • decoding=async
  • height
  • loading=lazy
  • src
  • width

Hero image:

  • alt
  • data-hero
  • decoding=async
  • height
  • src
  • width

Image using srcset:

  • alt
  • decoding=async
  • height
  • loading=lazy
  • sizes
  • srcset
  • width

Describe alternatives you've considered

These guidelines are fairly strict, we had considered having looser more granular validation rules for images trying to replicate specific amp-layout considerations, however for ease of development and for user understanding we have decided to start with more strict validation rules and allow for loosening of these restrictions in the future.

Additional context

For additional documents see this document about amp-img deprecation, and this document about allowing native img in valid amp documents.

rbeckthomas avatar Nov 02 '20 20:11 rbeckthomas

To be considered:

  • do not allow for ancestors that are amp- elements
  • do not allow for ancestors of template
  • consider limitations regarding amp-bind

honeybadgerdontcare avatar Nov 02 '20 21:11 honeybadgerdontcare

  1. do not allow for ancestors that are amp- elements

For a first revision yes, if an image has a amp- custom element ancestor, it must be a amp-img. This could be loosened in the future but would be a component by component change.

  1. do not allow for ancestors of template

Sound reasonable for a first revision, can re-visit after first phase.

  1. consider limitations regarding amp-bind

Which limitations are you thinking?

kristoferbaxter avatar Nov 02 '20 21:11 kristoferbaxter

  1. consider limitations regarding amp-bind

Which limitations are you thinking?

We weren't exactly sure and it's an action item to determine if any need to exist. We plan to follow up with @jridgewell or @choumx to see if they thought this would be something to consider.

In all things validation, we prefer to be more strict at first and open up later once we're sure that's the direction we want. The intention here is to confirm that this is okay.

honeybadgerdontcare avatar Nov 02 '20 21:11 honeybadgerdontcare

  1. do not allow for ancestors that are amp- elements

For a first revision yes, if an image has a amp- custom element ancestor, it must be a amp-img. This could be loosened in the future but would be a component by component change.

The Validator currently has a disallowed_ancestor [1] feature but not an allowed_ancestor. Is it a requirement to only allow some amp components to have this as a child when the time comes?

[1] https://github.com/ampproject/amphtml/blob/master/validator/validator.proto#L627

honeybadgerdontcare avatar Nov 02 '20 21:11 honeybadgerdontcare

We see a few somewhat common attributes added to img tags which aren't in this list. Do we want to allow any of these @rebeccanthomas / @kristoferbaxter ?

  • border
  • align
  • vspace / hspace
  • layout (I'm guessing this just just from the amp layout engine and we don't want it, but figured I'd ask).

Gregable avatar Dec 04 '21 00:12 Gregable

Can we also add importance?

westonruter avatar Dec 04 '21 01:12 westonruter

None of these seem problematic except for layout.

kristoferbaxter avatar Dec 04 '21 03:12 kristoferbaxter

There are a few others listed in MDN:

  • crossorigin
  • ismap
  • referrerpolicy
  • usemap

While align, hspace, and vspace are all deprecated, there are others which are also deprecated which don't seem harmful to allow:

  • name
  • longdesc

westonruter avatar Dec 04 '21 05:12 westonruter

@kristoferbaxter could you approve the final list below? From the thread, this is what we folks want to add:

  • border
  • align
  • vspace / hspace
  • importance
  • crossorigin
  • ismap
  • referrerpolicy
  • usemap
  • name
  • longdesc

banaag avatar Dec 06 '21 16:12 banaag

Approved! Thanks @banaag.

kristoferbaxter avatar Dec 06 '21 16:12 kristoferbaxter

I'd like to remove longdesc from the list. It is an URL which might be fetched by some useragents, which might represent a leak of the user's ip / query in prefetch. I'm not certain this is the case, but I think the risk combined with very low usage and the fact that it's deprecated means we can safely leave it out.

Gregable avatar Dec 06 '21 20:12 Gregable

Makes sense @Gregable, no need for caches to implement custom rules for a deprecated attribute.

kristoferbaxter avatar Dec 06 '21 21:12 kristoferbaxter

All the changes are checked-in. Should be uploaded to github during next validation rotation deployment.

banaag avatar Dec 07 '21 16:12 banaag

Now that this is done, and as per @honeybadgerdontcare 's mention, we should update external documentation before closing this. @rebeccanthomas, checking that is this on your radar.

Gregable avatar Dec 16 '21 22:12 Gregable

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 24 '22 03:12 stale[bot]