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

Enable generation of Transformed AMP pages #958

westonruter opened this issue Feb 14, 2018 · 2 comments


Copy link

commented Feb 14, 2018

We can speed up the serving of AMP pages by pre-rendering them and serving them in the same way they are served from an AMP cache. In short, the processes performed by the AMP Optimizer should be ported into the plugin. Something important to note here that when pre-rendering is performed, there will somewhat counter-intuitively need to be a paired mode even when a site is AMP Canonical. The reason is:

Warning: optimized AMPs will no longer be valid AMPHTML. Don't use this to optimize AMPs meant for being used by platforms such as Google Search.

So the pre-rendered AMP version of a page would would be canonical URL, and there would be an amphtml link to the same exact content without the pre-rendering logic applied. This is similar to the existing paired mode works, except here the canonical version is generated from the AMP version via pre-rendering. So it's important to note that this pre-rendering should not be offered on sites that are not using Canonical AMP, as it would not make sense to have a pre-rendered AMP version alongside the valid AMP and the non-AMP content.

As for where the pre-rendering should be performed, it should be done right after the call to AMP_Content_Sanitizer::sanitize_document() in AMP_Theme_Support::prepare_response():

For example:

$assets = AMP_Content_Sanitizer::sanitize_document( $dom, self::$sanitizer_classes, $args );
self::ensure_required_markup( $dom );
if ( ! is_amp_endpoint() ) {
    do_the_function_that_runs_amp_prerendering( $dom ); // 👈

Since is_amp_endpoint() currently always returns true if amp_is_canonical() then this will need to be amended to support the case for pre-rendering. In other words, even on a canonical-site there will be the need for separate AMP endpoint URLs. So the if ( amp_is_canonical() ) { return true; } conditional may need to be removed here. Related to #934.

@postphotos postphotos added the Sprint 6 label May 17, 2018

@postphotos postphotos added this to Definition in v1.0 May 17, 2018

@westonruter westonruter moved this from Definition to Ready for review in v1.0 May 22, 2018

@westonruter westonruter moved this from Ready for review to Definition in v1.0 May 22, 2018

@westonruter westonruter removed this from Definition in v1.0 Jun 26, 2018

@amedina amedina changed the title Add AMP pre-rendering to speed up Canonical AMP sites Enable generation of Optimized AMP pages Aug 21, 2018

@westonruter westonruter added this to the v1.1 milestone Dec 5, 2018

@westonruter westonruter changed the title Enable generation of Optimized AMP pages Enable generation of Transformed AMP pages Feb 20, 2019


This comment has been minimized.

Copy link
Member Author

commented Feb 20, 2019

In AMP the SSR is also termed “transformed”. The validator has just landed with some recognition of this which we're not explicitly skipping from the generated spec: 51d81ab.

We'll potentially need to revert that and add some awareness of a transformed mode. Or potentially we'd still not care about the transformed rules since we'd apply them in a sanitizer after the whitelist runs.

@westonruter westonruter removed this from the v1.1 milestone Mar 6, 2019


This comment has been minimized.

Copy link
Member Author

commented Apr 21, 2019

See also

We need to make sure the Transformed AMP sanitizer, along with the other sanitizers, are turned into a separate package which can be used standalone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.