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
Try using AMP Optimizer if available #1780
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1780 +/- ##
===========================================
+ Coverage 69.11% 83.56% +14.45%
===========================================
Files 714 770 +56
Lines 12498 12997 +499
===========================================
+ Hits 8638 10861 +2223
+ Misses 3860 2136 -1724
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This comment has been minimized.
This comment has been minimized.
100387d
to
e080946
Compare
1cc6acd
to
b8f3943
Compare
Let me know if you need any assistance with getting the Optimizer to work. |
// Needed for \AmpProject\Optimizer\Transformer\AmpRuntimeCss. | ||
$content = str_replace( '</head>', '<style amp-runtime></style></head>', $content ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TransformedIdentifier
transformer is what is is responsible for flagging a document as being transformed which would then allow style[amp-runtime]
, which you are including. So that seems OK. But injecting the element in this way seems not ideal.
Flagging a document as being transformed
is normally bound up with a document also going through SSR. Hence the AmpRuntimeCss
, ServerSideRendering
, and TransformedIdentifier
form a pair: https://github.com/ampproject/amp-wp/blob/8d5f29f1f22e6623789dca250901cff0a559e590/includes/class-amp-theme-support.php#L2182-L2194
The ServerSideRendering
transformer adds the style[amp-runtime]
element. However, why is this not the responsibility of the AmpRuntimeCss
transformer?
@schlessera Should this logic be moved from ServerSideRendering
to AmpRuntimeCss
?
// Emit the amp-runtime marker to indicate that we're applying server side rendering in the document.
$ampRuntimeMarker = $document->createElement(Tag::STYLE);
$ampRuntimeMarker->setAttribute(Attribute::AMP_RUNTIME, '');
$document->head->insertBefore($ampRuntimeMarker, $document->head->hasChildNodes() ? $document->head->firstChild : null);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ServerSideRendering
does all the checks to see if SSR can be done, and then tags the runtime to denote that it should be inlined.
The AmpRuntimeCss
is responsible for inlining (or linking) the runtime CSS, but only does so if the SSR gave its okay.
That models the way it is also handled in the amp-toolbox
implementation.
If we move the generation of the element into the AmpRuntimeCss
transformer, we'd need another element/attribute of some sort to provide the information whether inlining should happen or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that stories can't do SSR, should the AmpRuntimeCss be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that stories can't do SSR, should the AmpRuntimeCss be done?
I don't know too much about AMP SSR, so if you can give me some guidance that would be great :-)
e651106
to
2048eaf
Compare
Summary
Relevant Technical Choices
To-do
Fixes #1276