amp.dev icon indicating copy to clipboard operation
amp.dev copied to clipboard

Document how to optimize CLS for amp-access and amp-subscription

Open sebastianbenz opened this issue 4 years ago • 7 comments

We need guidance on how to avoid content shifts on load when using amp-access / amp-subscriptions. Not sure whether this should go into the respective component docs or whether we should have a standalone guide on how to avoid CLS issues with AMP.

//cc @CrystalOnScript @patrickkettner @kristoferbaxter

sebastianbenz avatar Mar 16 '21 17:03 sebastianbenz

@sebastianbenz @kristoferbaxter who would be the right person to provide this guidance?

patrickkettner avatar Apr 13 '21 21:04 patrickkettner

I should be able to help with this during the current week. Will schedule some time.

kristoferbaxter avatar Apr 14 '21 01:04 kristoferbaxter

@patrickkettner can you look into this as well. Playing around with amp-access and the different options should give you an idea of the CLS challenges.

sebastianbenz avatar Apr 14 '21 07:04 sebastianbenz

This page https://www.bbc.com/urdu.amp seems to be using amp-access in the viewport perhaps to handle consent or something and this cause a CLS over threshold alone.

gilbertococchi avatar Apr 23 '21 16:04 gilbertococchi

Pinging @ampproject/wg-performance on this thread too, we should take a look at amp-access and see if we can:

  1. Improve the default behaviour
  2. Provide better guidance around usage
  3. Prohibit usage that would break CWV metrics
  4. Make it more clear to document developers when usage will likely cause poor metrics results.

kristoferbaxter avatar Apr 23 '21 18:04 kristoferbaxter

Looking at https://www.bbc.com/urdu.amp it seems like ads are hidden by default, but will be shown for "normal users" causing the CLS. This is a typical example for where it is impossible to avoid CLS for all your users when using amp-access.

Publishers in this case have a few options:

  • optimize the default for the majority of their users
  • avoid showing/hiding content in the first viewport (at least on mobile)

But depending on their use case this might not be feasible. We should explicitly document these issues though for amp-access and amp-subscription. Maybe a separate guide we can link to from both component docs would be good.

sebastianbenz avatar Apr 23 '21 18:04 sebastianbenz

Good point.

It would be great to at least warn about the potential issues while using these components in the first viewport potentially causing CLS issues.

I am not sure about the approach to avoid showing content using these components in the viewport because I've seen amp-access/amp-suscription being used to detect login state to be updated in the header without causing any Layout Shift or minimal.

gilbertococchi avatar Apr 26 '21 12:04 gilbertococchi