inc2734 / wp-page-speed-optimization
A library for WordPress.
Installs: 5 834
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 3
Requires
- php: >=7.4
Requires (Dev)
- dev-master
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.3
- 2.1.2
- 2.1.0
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.7.5
- 0.7.3
- 0.7.2
- 0.7.1
- 0.7.0
- 0.6.1
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.1
- 0.1.0
- dev-dependabot/npm_and_yarn/babel/traverse-7.23.2
- dev-dependabot/npm_and_yarn/postcss-8.4.31
- dev-dependabot/npm_and_yarn/shell-quote-1.8.1
- dev-release/0.7
This package is auto-updated.
Last update: 2024-10-23 10:19:58 UTC
README
Install
$ composer require inc2734/wp-page-speed-optimization
How to use
Initialize (Require)
<?php
// When Using composer auto loader
new Inc2734\WP_Page_Speed_Optimization\Bootstrap();
Add defer attribute
add_filter( 'inc2734_wp_page_speed_optimization_defer_scripts', function( $handles ) {
return array_merge( $handles, [
get_template(),
get_stylesheet(),
] );
} );
Add async attribute
add_filter( 'inc2734_wp_page_speed_optimization_async_scripts', function( $handles ) {
return array_merge( $handles, [
'comment-reply',
'wp-embed',
] );
} );
Optimize jQuery loading
Load jQuery and other scripts as defer + head as much as possible.
add_filter( 'inc2734_wp_page_speed_optimization_optimize_jquery_loading', '__return_true' );
Use HTTP/2 Server Push
add_filter( 'inc2734_wp_page_speed_optimization_do_http2_server_push', '__return_true' );
add_filter( 'inc2734_wp_page_speed_optimization_http2_server_push_handles', function( $handles ) {
return $handles;
} );
Use link prefetching
add_filter( 'inc2734_wp_page_speed_optimization_link_prefetching', '__return_true' );
add_filter( 'inc2734_wp_page_speed_optimization_link_prefetching_selector', '.l-header, .l-contents__main' );
add_filter( 'inc2734_wp_page_speed_optimization_link_prefetching_interval', 2000 );
add_filter( 'inc2734_wp_page_speed_optimization_link_prefetching_connections', 1 );
Output CSS to head
add_filter( 'inc2734_wp_page_speed_optimization_output_head_styles', function( $handles ) {
return array_merge( $handles, [
get_template(),
get_stylesheet(),
] );
} );
Preload Styles
add_filter( 'inc2734_wp_page_speed_optimization_preload_stylesheets', function( $handles ) {
$wp_styles = wp_styles();
$preload_handles = $wp_styles->queue;
if ( in_array( get_template(), $preload_handles ) ) {
unset( $preload_handles[ get_template() ] );
}
if ( in_array( get_stylesheet(), $preload_handles ) ) {
unset( $preload_handles[ get_stylesheet() ] );
}
return array_merge( $handles, $preload_handles );
} );
Use browser cache with .htaccess
// If `set-expires-header` customize setting
add_action( 'customize_save_set-expires-header', function( $customize_setting ) {
if ( $customize_setting->post_value() === $customize_setting->value() ) {
return;
}
\Inc2734\WP_Page_Speed_Optimization\Helper\write_cache_control_setting( (bool) $customize_setting->post_value() );
} );
Cache nav menus
// If using nav menu caching, remove all current classes.
add_filter( 'inc2734_wp_page_speed_optimization_caching_nav_menus', '__return_true' );
Cache sidebars
// in functions.php
add_filter( 'inc2734_wp_page_speed_optimization_caching_sidebars', '__return_true' );
// in template
\Inc2734\WP_Page_Speed_Optimization\Page_Speed_Optimization\Helper\dynamic_sidebar( 'footer-widget-area' );
Async loading of attachment image
add_filter( 'inc2734_wp_page_speed_async_attachment_images', '__return_true' );
Async loading of content image
add_filter( 'inc2734_wp_page_speed_async_content_images', '__return_true' );