Skip to content

Commit ec6922a

Browse files
committed
Optimize css resource loading
1 parent 2f062c1 commit ec6922a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

source/wp-content/themes/wporg-main-2022/functions.php

+14
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
* Actions and filters.
1919
*/
2020
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' );
21+
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\maybe_dequeue_assets' );
2122
add_action( 'init', __NAMESPACE__ . '\register_shortcodes' );
2223
add_filter( 'wp_img_tag_add_loading_attr', __NAMESPACE__ . '\override_lazy_loading', 10, 2 );
2324
add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\update_site_breadcrumbs' );
2425
add_filter( 'render_block_core/site-title', __NAMESPACE__ . '\use_parent_page_title', 10, 3 );
2526
add_filter( 'render_block_data', __NAMESPACE__ . '\update_header_template_part_class' );
2627
add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' );
2728

29+
// Remove Jetpack CSS on frontend
30+
add_filter( 'jetpack_implode_frontend_css', '__return_false', 99 );
31+
2832
/**
2933
* Enqueue scripts and styles.
3034
*/
@@ -96,6 +100,16 @@ function enqueue_assets() {
96100
}
97101
}
98102

103+
/**
104+
* Dequeue or deregister some scripts and styles on frontend for performance.
105+
*/
106+
function maybe_dequeue_assets() {
107+
if ( ! is_user_logged_in() && is_front_page() ) {
108+
wp_deregister_style( 'dashicons' );
109+
wp_deregister_style( 'wp-mediaelement' );
110+
}
111+
}
112+
99113
/**
100114
* Load the shortcodes available for the theme.
101115
*/

0 commit comments

Comments
 (0)