From ec6922a69c84516d4a4571e1dcf6a8a00b363fbc Mon Sep 17 00:00:00 2001 From: Adam Wood <1017872+adamwoodnz@users.noreply.github.com> Date: Fri, 27 Oct 2023 17:05:01 +1300 Subject: [PATCH] Optimize css resource loading --- .../themes/wporg-main-2022/functions.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source/wp-content/themes/wporg-main-2022/functions.php b/source/wp-content/themes/wporg-main-2022/functions.php index 72ae61d0..821a72c3 100644 --- a/source/wp-content/themes/wporg-main-2022/functions.php +++ b/source/wp-content/themes/wporg-main-2022/functions.php @@ -18,6 +18,7 @@ * Actions and filters. */ add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' ); +add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_dequeue_assets' ); add_action( 'init', __NAMESPACE__ . '\register_shortcodes' ); add_filter( 'wp_img_tag_add_loading_attr', __NAMESPACE__ . '\override_lazy_loading', 10, 2 ); add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' ); @@ -25,6 +26,9 @@ add_filter( 'render_block_data', __NAMESPACE__ . '\update_header_template_part_class' ); add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); +// Remove Jetpack CSS on frontend +add_filter( 'jetpack_implode_frontend_css', '__return_false', 99 ); + /** * Enqueue scripts and styles. */ @@ -96,6 +100,16 @@ function enqueue_assets() { } } +/** + * Dequeue or deregister some scripts and styles on frontend for performance. + */ +function maybe_dequeue_assets() { + if ( ! is_user_logged_in() && is_front_page() ) { + wp_deregister_style( 'dashicons' ); + wp_deregister_style( 'wp-mediaelement' ); + } +} + /** * Load the shortcodes available for the theme. */