amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Provide document height to viewer

Open RJSumi opened this issue 9 years ago • 13 comments

The viewer needs the document height from the runtime. I understand that this had some performance issues in the past. When might this be made available again?

cc @dvoytenko

RJSumi avatar Dec 07 '16 21:12 RJSumi

Is this likely to get any traction soon, or is this infeasible?

RJSumi avatar Jan 23 '17 18:01 RJSumi

A few things this requires:

  • [ ] Initial document heigh in documentLoaded
  • [ ] A new ping every time an element resizes

Alternatively, we could allow the viewer to request the height, but it'd be a little less performant. @muxin or @chenshay, would you like to take this?

jridgewell avatar Jan 23 '17 18:01 jridgewell

@RJSumi Do you need resizes?

cramforce avatar Jan 23 '17 18:01 cramforce

@jridgewell For the first bullet point, do you mean measuring the document height when we're about to send the documentLoaded message?

muxin avatar Jan 23 '17 22:01 muxin

Yup, it should be available pretty early in Viewport.

jridgewell avatar Jan 23 '17 22:01 jridgewell

So when we're about to send documentLoaded message, we should have built every element so it's a good time to measure the document height?

muxin avatar Jan 23 '17 22:01 muxin

we should have built every element so it's a good time to measure the document height?

No. But, AMP requires every these elements to have a defined width/height, so we should know how tall it is even if it's not built.

jridgewell avatar Jan 23 '17 23:01 jridgewell

@jridgewell But there are other non-amp elements, we could also measure the heights of non-amp elements at that time?

muxin avatar Jan 23 '17 23:01 muxin

They should already have there size by this time.

jridgewell avatar Jan 23 '17 23:01 jridgewell

OK, thanks @jridgewell I can try to measure the document height for the initial height in documentLoaded and the updated height in every resizes. @RJSumi In what message do you need the document height value?

muxin avatar Jan 23 '17 23:01 muxin

Messaged with @RJSumi offline, will be sending documentHeight like {height: <number>} message to viewer.

muxin avatar Jan 24 '17 00:01 muxin

Two challenges to keep in mind:

  1. Performance is very much an issue. However, provided we can control when measurements are done and sent over, we should be able to optimize it on our side. We currently don't have 100% reliable "mutated" pings, but we have some signals that would help us to do these measurements less often. We can even try to measure height after each resources pass (with basic debouncing) and see how much performance affect it has.
  2. scrollHeight could yield wrong values in some circumstances. I believe most of issues were around old iOS viewport (iOS <= 8) and should be now addressed for newer versions. However, testing is needed to confirm.

dvoytenko avatar Jan 24 '17 18:01 dvoytenko

Closed via https://github.com/ampproject/amphtml/pull/7327

muxin avatar Feb 21 '17 21:02 muxin