Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prerender amp-video poster image. #25456

Merged
merged 3 commits into from
Nov 7, 2019

Conversation

gmajoulet
Copy link
Contributor

amp-video used to load the poster image in prerender (#1657 + #1718).
When introducing prerendering for cached videos (#12193 + #17493), we broke the case for prerendering the poster when the video is not cached.

If the video has cached sources OR a poster image, it should allow prerendering.

It is safe to prerender a video with a poster image but no cached source, as the amp-video.layoutCallback will only propagate the cached source until the viewer is visible (source).

Fixes #25446

@sparhami
Copy link

sparhami commented Nov 5, 2019

I don't believe this is safe as-is, allowing prerender will cause the element to be built, which will trigger preconnectCallback, which leaks information by establishing a connection to the video's origin.

Perhaps we could check if the current document state is prerender in preconnectCallback, and skip the preconnect if so? It doesn't sound like a great idea to me, but I think as long as we document it and maybe add a test it should be okay.

@gmajoulet
Copy link
Contributor Author

Great catch, thanks!
I updated the preconnectCallback to connect to the first cached URL (or nothing) during prerender.

const {element} = this;
const sources = toArray(childElementsByTag(element, 'source'));
sources.push(element);
for (let i = 0; i < sources.length; i++) {
if (this.isCachedByCDN_(sources[i])) {
return true;
return sources[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This returns an element, not a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and added unit tests for preconnectCallback.

@newmuis
Copy link
Contributor

newmuis commented Nov 6, 2019

Don't we also need to check whether the poster is served off of the cache?

Copy link
Contributor Author

@gmajoulet gmajoulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we also need to check whether the poster is served off of the cache?

This wasn't part of the original implementation (#1657 + #1718), and isn't done by amp-img either. My guess is that we rely on the AMP cache that always rewrites these URLs during ingestion.

PTAL

const {element} = this;
const sources = toArray(childElementsByTag(element, 'source'));
sources.push(element);
for (let i = 0; i < sources.length; i++) {
if (this.isCachedByCDN_(sources[i])) {
return true;
return sources[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, and added unit tests for preconnectCallback.

@gmajoulet gmajoulet merged commit 1cc9bb1 into ampproject:master Nov 7, 2019
@gmajoulet gmajoulet deleted the video_prerender_poster branch November 7, 2019 19:06
micajuine-ho pushed a commit to micajuine-ho/amphtml that referenced this pull request Dec 27, 2019
* Prerender amp-video poster image.

* Preconnect to the first cached URL during prerendering.

* More unit tests for preconnect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Story video poster image not loading during prerendering
5 participants