Skip to content

Defer CSS handling to AMP plugin when is_amp_endpoint()#41

Open
westonruter wants to merge 1 commit intoAutomattic:masterfrom
xwp:add/amp-theme-support
Open

Defer CSS handling to AMP plugin when is_amp_endpoint()#41
westonruter wants to merge 1 commit intoAutomattic:masterfrom
xwp:add/amp-theme-support

Conversation

@westonruter
Copy link
Copy Markdown

When in an AMP response, prevent needlessly concatenating and minifying CSS because the AMP plugin does this automatically; beyond this, the AMP plugin also does tree shaking to strip out CSS rules that do not apply to the current page, and the resulting CSS from external stylesheets, style elements, and style attributes is then all combined into the one style[amp-custom] element. This check prevents the AMP plugin from having to issue an HTTP request to fetch the contents of the concatenated stylesheet.

Note that this is_amp_endpoint() check is done here at runtime instead of in css_concat_init() because it must be called after the parse_query action in order to determine whether the response will be served as AMP or not. Note also that this change only applies to sites that enable AMP theme support, as the classic AMP post templates do not use WP_Styles at all.

See https://github.com/Automattic/amp-wp/wiki/Adding-Theme-Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant