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

AMP: Stylesheet 'jetpack-widget-social-icons-styles' is enqueued even if Social Icons widget is never used #10862

Closed
westonruter opened this issue Dec 6, 2018 · 0 comments
Assignees
Labels
[Feature] Extra Sidebar Widgets [Type] Bug When a feature is broken and / or not performing as intended

Comments

@westonruter
Copy link
Contributor

The stylesheet for the Social Icons widget is enqueued unconditionally even when the widget not used on the page:

/**
* Styles for front-end widget.
*/
public function enqueue_icon_scripts() {
wp_enqueue_style( 'jetpack-widget-social-icons-styles', plugins_url( 'social-icons/social-icons.css', __FILE__ ), array(), '20170506' );
}

Normally jetpack_implode_frontend_css would be true so this issue would not be noticed. However, when serving AMP pages, Jetpack opts-out of serving the concatenated CSS to facilitate the AMP plugin's CSS tree shaker to make it easier to stay below 50KB:

// disable imploding CSS
add_filter( 'jetpack_implode_frontend_css', '__return_false' );

This then causes the CSS to be needlessly output on the frontend, as seen in the style[amp-custom] manifest comment:

253 B (40%): link#jetpack-widget-social-icons-styles-css[rel=stylesheet][id=jetpack-widget-social-icons-styles-css][href=https://weston.ruter.net/wp-content/plugins/jetpack/modules/widgets/social-icons/social-icons.css?ver=20170506][type=text/css][media=all]

There are 253 bytes, the .screen-reader-text rule, which survive the tree-shaking process. While this is very small, every byte counts when there is a 50KB limit.

And for sites that have other reasons to disable jetpack_implode_frontend_css, this needless enqueue slows down the performance of the frontend.

@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Extra Sidebar Widgets labels Dec 7, 2018
@jeherve jeherve self-assigned this Dec 7, 2018
jeherve added a commit that referenced this issue Dec 7, 2018
Fixes #10862

We should only enqueue scripts and styles on pages and admin pages where the elements are needed.
zinigor pushed a commit that referenced this issue Dec 25, 2018
Fixes #10862

We should only enqueue scripts and styles on pages and admin pages where the elements are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extra Sidebar Widgets [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

No branches or pull requests

2 participants