PageSpeed Scores & Optimization

How to get…

GTMetrix Scores of 100/97
Pingdom Performance Grade of 100
Pagespeed Insights Scores of 91/90


Install These Plugins

Autoptimize Plugin
Async Javascript Plugin

Add this code to your .htaccess file

# GZIP Compression

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary

# Leverage Browser Caching

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

# Cache Common Files

<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|swf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$">
Header set Cache-Control "max-age=2592000, public"

# Enable Keepalive

<ifModule mod_headers.c>
Header set Connection keep-alive

# Enable Vary: Accept-Encoding

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding



Add The Code Below To The Bottom Of Functions.php File or Custom Function Plugin

*IMPORTANT – If you have Debug set to TRUE in WP-Config, the “jquery code” will throw a php error.  I’ll try to get a fix, but this code is really popular.

(may be added to Socrates Toolkit Shortly)

//Remove Query Strings from Static Sources

function soc_remove_qstrings_css_js( $src ) {
	if ( strpos( $src, 'ver=' ) ) {
		$src = remove_query_arg( 'ver', $src );
	return $src;

add_filter( 'style_loader_src', 'soc_remove_qstrings_css_js', 9999 );
add_filter( 'script_loader_src', 'soc_remove_qstrings_css_js', 9999 );

// Replace Jquery - Will Break Masonry Template
function soc_remove_jquery() {
	if (!is_admin()) {
		wp_register_script('jquery', '', false, '1.8.3');
add_action('init', 'soc_remove_jquery');

Video Placeholder Trick

If you don’t want a video to load upon page load, use this code to make it load upon click.

Just take a screenshot of your video, upload it and replace the sample video poster link with the image path.  Then replace the source src with your MP4 link.

<div align="center">
<video poster="" preload="none" controls="controls" width="100%" height="auto">
<source src="" type="video/mp4" preload="none" />

Contact Form 7

If you’re using Contact Form 7, there code loads on every page.. Here’s a trick to block their code from loading except on their form pages. Click Here.