Speeding up my WordPress Site – Part 3

One of the biggest issues on my site is render-blocking JavaScript and CSS in above-the-fold content. As you can see, I use jQuery only for my portfolio pages: I use a Codrops script for enhance mobile in my general work page and flexslider plugin for an specific work page.

My first step was to call my JS compress file only for those two pages, this reduce http’s requests on my blog pages to zero.

if ( is_singular( 'work' ) || is_page( 'work' ) )

After that, I had to start checking out Contact Form 7 plugin. This amazing plugin is not very helpful with performance. It generates 5 http requests: 4 JS and 1 CSS. First thing I do was to call it only for pages it really need it, it meant on the Home and Contact page. For this, I used this snippet on my functions.php page.

add_filter( 'wpcf7_load_js', '__return_false' );
add_filter( 'wpcf7_load_css', '__return_false' );

And this at the header of the Home and Contact page:

if ( function_exists( 'wpcf7_enqueue_scripts' ) ) { wpcf7_enqueue_scripts(); }

I decided no to load the CSS stylesheet.After analysing the code, I decided it wasn’t a really structural part of the plugin, specially for my site where I use it only for a simple form. So, I integrated directly into my SCSS code and decided to test for future versions of the plugin and see if it can break my site. I have to confess this was the lazy solution, I should’ve just build a form by hand, eliminate it from Home page and let it just for the Contact page.

Finally, I decided to test a new filter from WordPress 4.1:

add_filter( 'script_loader_tag', function ( $tag, $handle ) {
return str_replace( ' src', ' async src', $tag );
}, 10, 2 );

As I really don’t need JS for building my DOM, I decided to call all my JS files on a async mode. So far, I really don’t have a lot of experience and I don’t know how it can behave on a larger site, but it looks to work pretty well.

Here, I saw huge changes, my site changed from 92/100 for Desktop and 75/100 for mobile to 96/100 for Desktop and 90/100 for mobile.

I want to be clear, It’s been just a week after those changes and I’m still monitoring possible unexpected outcomes. If you have any comments or suggestions, don’t hesitate, I have the comments area blocked but only for spam issues.