Provide document height to viewer
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
Is this likely to get any traction soon, or is this infeasible?
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?
@RJSumi Do you need resizes?
@jridgewell For the first bullet point, do you mean measuring the document height when we're about to send the documentLoaded message?
Yup, it should be available pretty early in Viewport.
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?
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 But there are other non-amp elements, we could also measure the heights of non-amp elements at that time?
They should already have there size by this time.
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?
Messaged with @RJSumi offline, will be sending documentHeight like {height: <number>} message to viewer.
Two challenges to keep in mind:
- 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.
scrollHeightcould 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.
Closed via https://github.com/ampproject/amphtml/pull/7327