amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

amp-story: Relative image URLs in the bookend break when served from an AMP cache.

Open flaviori opened this issue 7 years ago • 5 comments

When serving the following URL from the AMP Cache https://www-nationalgeographic-com.cdn.ampproject.org/c/s/www.nationalgeographic.com/amp-stories/travel/10-iconic-places-to-photograph/ the thumbnail images in the bookend won't load, but they load as expected when the page is loaded from origin https://www.nationalgeographic.com/amp-stories/travel/10-iconic-places-to-photograph/ uUyVVLQoOoA

I noticed the images URLs are relative, so it might be that these are not properly absolutified by the cache, but I haven't verified. If relative URLs are in fact not supported, then there should be a validation error, but I believe we do want to support them.

flaviori avatar Oct 29 '19 21:10 flaviori

The image URL was: assets/01-iconic-american-destinations.jpg

flaviori avatar Oct 29 '19 21:10 flaviori

Thanks for filing this one!

I think the issue is something different though. During ingestion by the AMP cache, the img assets/01-iconic-american-destinations.jpg is not present in the DOM as it will be lazy loaded as users get close to the bookend. So this img will never get fetched and cached. The URL is fine as it tries to load the image from the AMP cache, which is the expected behavior. But the image didn't get cached.

In an ideal world, we'd want to have these images served from the AMP cache. But since the bookend configuration is dynamic and changes depending on what the publisher's backend returns, this might not be achievable. Do we want to force the relative URLs to be loaded from the publisher's origin, when served from the cache?

cc @Gregable

gmajoulet avatar Nov 12 '19 15:11 gmajoulet

Greg and I synced offline:

When served from an AMP cache, we compute the absolute URL from the relative URL, using the current cache host. In this example, the relative URL is assets/01-iconic-american-destinations.jpg which resolves to https://www-nationalgeographic-com.cdn.ampproject.org/c/s/www.nationalgeographic.com/amp-stories/travel/10-iconic-places-to-photograph/assets/01-iconic-american-destinations.jpg Here, we replace the /c/s into /i/s. The cache will either serve the image if already cached, or fetch it. https://www-nationalgeographic-com.cdn.ampproject.org/i/www.nationalgeographic.com/amp-stories/travel/10-iconic-places-to-photograph/assets/01-iconic-american-destinations.jpg

We should also look into using extra parameters to get a resized image and save users bandwidth: /ii/w${width}/s

gmajoulet avatar Nov 13 '19 00:11 gmajoulet

Sorry, can you clarify if this is something we need to do on the runtime side?

Enriqe avatar Nov 13 '19 16:11 Enriqe

Yes my previous comment describes what our code should do :))

gmajoulet avatar Nov 13 '19 17:11 gmajoulet