Skip to content

Instantly share code, notes, and snippets.

@KoolPal
Forked from ankyit/WordPress Performance.txt
Created April 21, 2020 12:40
Show Gist options
  • Save KoolPal/57f6d5bea17c620f3a5555204f1a3aaf to your computer and use it in GitHub Desktop.
Save KoolPal/57f6d5bea17c620f3a5555204f1a3aaf to your computer and use it in GitHub Desktop.
WordPress Performance
### Sites:
https://gtmetrix.com/
https://developers.google.com/speed/pagespeed/insights/
### Plugins
https://wordpress.org/plugins/query-monitor/
https://wordpress.org/plugins/autoptimize/
https://wordpress.org/plugins/wp-super-cache/
https://wordpress.org/plugins/ewww-image-optimizer/
https://wordpress.org/plugins/jetpack/
https://wordpress.org/plugins/wp-optimize/
#### Nginx Cache
# Expire rules for static content
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
##### Optimize woocommerce
/**
* Optimize WooCommerce Scripts
* Remove WooCommerce Generator tag, styles, and scripts from non WooCommerce pages.
*/
add_action( 'wp_enqueue_scripts', 'child_manage_woocommerce_styles', 99 );
function child_manage_woocommerce_styles() {
//remove generator meta tag
remove_action( 'wp_head', array( $GLOBALS['woocommerce'], 'generator' ) );
//first check that woo exists to prevent fatal errors
if ( function_exists( 'is_woocommerce' ) ) {
//dequeue scripts and styles
if ( ! is_woocommerce() && ! is_cart() && ! is_checkout() ) {
wp_dequeue_style( 'woocommerce_frontend_styles' );
wp_dequeue_style( 'woocommerce_fancybox_styles' );
wp_dequeue_style( 'woocommerce_chosen_styles' );
wp_dequeue_style( 'woocommerce_prettyPhoto_css' );
wp_dequeue_script( 'wc_price_slider' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-add-to-cart' );
wp_dequeue_script( 'wc-cart-fragments' );
wp_dequeue_script( 'wc-checkout' );
wp_dequeue_script( 'wc-add-to-cart-variation' );
wp_dequeue_script( 'wc-single-product' );
wp_dequeue_script( 'wc-cart' );
wp_dequeue_script( 'wc-chosen' );
wp_dequeue_script( 'woocommerce' );
wp_dequeue_script( 'prettyPhoto' );
wp_dequeue_script( 'prettyPhoto-init' );
wp_dequeue_script( 'jquery-blockui' );
wp_dequeue_script( 'jquery-placeholder' );
wp_dequeue_script( 'fancybox' );
wp_dequeue_script( 'jqueryui' );
}
}
}
/* Defer Parsing of Javascript*/
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url;
return "$url' defer ";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
/* JQUERY CDN */
// Load Jquery from CDN
function modify_jquery()
{ if (!is_admin())
{ wp_deregister_script('jquery');
wp_register_script('jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js', false, '1.12.4');
wp_enqueue_script('jquery');
}
}
add_action('init', 'modify_jquery');
## reduce the post revisions wp-config.php
define('WP_POST_REVISIONS', 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment