<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jason Johnson on Medium]]></title>
        <description><![CDATA[Stories by Jason Johnson on Medium]]></description>
        <link>https://medium.com/@jasonmj?source=rss-3cf5371be3c3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rx2uFevzURRHhM8V.</url>
            <title>Stories by Jason Johnson on Medium</title>
            <link>https://medium.com/@jasonmj?source=rss-3cf5371be3c3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 10:51:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jasonmj/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimizing WordPress for PageSpeed]]></title>
            <link>https://medium.com/@jasonmj/optimizing-wordpress-for-pagespeed-16812e5f1434?source=rss-3cf5371be3c3------2</link>
            <guid isPermaLink="false">https://medium.com/p/16812e5f1434</guid>
            <category><![CDATA[website-speed]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Jason Johnson]]></dc:creator>
            <pubDate>Fri, 06 Jan 2017 16:51:47 GMT</pubDate>
            <atom:updated>2017-01-06T20:27:27.795Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently attended a WordPress meet-up on speed optimization where we talked about using caching to improve Google PageSpeed scores. I presented an example site that I had just built with best practices and a good score, but questions emerged on how to approach legacy sites with lots of plugins and less than ideal conditions.</p><p>Our local SEO expert in the crowd suggested that metric for deciding to improve your page PageSpeed is a score of <strong>40 or less</strong>. Under these circumstances your ranking may be compromised by your score.</p><p>So I decided to look at the score one of my older, more plugin bloated sites… it wasn’t good:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1eQrgOwtyzjbrfmWz4iEPg.jpeg" /></figure><p>Ok, lots of room for improvement here. I added expires headers to my <strong>.htaccess</strong> file to resolve the browser caching issues:</p><pre># begin expires<br>expiresactive on<br>expiresdefault “access plus 10 days”<br>expiresbytype text/css “access plus 1 week”<br>expiresbytype text/plain “access plus 1 month”<br>expiresbytype image/svg+xml “access 1 month”<br>expiresbytype image/gif “access plus 1 month”<br>expiresbytype image/png “access plus 1 month”<br>expiresbytype image/jpeg “access plus 1 month”<br>expiresbytype application/x-javascript “access plus 1 month”<br>expiresbytype application/javascript “access plus 1 week”<br>expiresbytype application/x-icon “access plus 1 year”<br># end expires</pre><p>Then, I changed all of my <strong>wp_enqueue_script()</strong> calls to make sure they load JavaScript in the footer. For example, a script in my functions.php file needed to change from this:</p><pre>wp_enqueue_script(‘site-search’, get_stylesheet_directory_uri() . ‘/js/site-search.js’);</pre><p>To reflect a more declarative version of <a href="https://developer.wordpress.org/reference/functions/wp_enqueue_script/"><strong>wp_enqueue_script()</strong></a> that includes jQuery as it’s dependency argument and the true boolean as the last argument, $in_footer:</p><pre>wp_enqueue_script(‘site-search’, get_stylesheet_directory_uri() . ‘/js/site-search.js’, [‘jquery’], NULL, true);</pre><p>In some cases, you’ll also want to control the order in which scripts are enqueued by adding a priority to the <a href="https://developer.wordpress.org/reference/functions/add_action/"><strong>add_action()</strong></a> function:</p><pre>add_action( $tag, $function_to_add, $priority, $accepted_args)</pre><p>The default priority is 10, lower numbers are higher priority and get executed earlier, while higher numbers are executed later.</p><p>So after quite a bit of enqueueing cleanup, I added a snippet to enqueue jQuery in the footer too:</p><pre>// Defer jQuery to Footer<br>add_action( ‘wp_enqueue_scripts’, ‘defer_jquery’ );<br>function defer_jquery() {<br>  if ( !current_user_can( ‘edit_pages’ ) ) {<br>    wp_deregister_script( ‘jquery’ );<br>    wp_register_script( ‘jquery’, includes_url(https://medium.com/%E2%80%98/js/jquery/jquery.js%E2%80%99), false, NULL, true );<br>    wp_enqueue_script( ‘jquery’ );<br>  }<br>}</pre><p>In this code, I’m using <a href="https://developer.wordpress.org/reference/functions/wp_deregister_script/"><strong>wp_deregister_script()</strong></a> to override the default enqueue args with those that will load jQuery in the footer instead.</p><p><strong>Warning:</strong> <em>this code has lots of potential to break things on your site, so you’ll want to be prepared to debug from the console after enabling it.</em></p><p>If you’re lucky, you won’t see any errors, but if you find anything stating that jQuery is not defined, you’ve still got some enqueuing adjustment to do. It’s possible to use the same method of dequeueing jQuery with to update how scripts outside of your child theme are loaded.</p><p>For my next trick, I added both <a href="https://wordpress.org/plugins/wp-super-cache/"><strong>WP Super Cache</strong></a> and <a href="https://wordpress.org/plugins/autoptimize/"><strong>Autoptimize</strong></a>. It’s really best to wait on doing this until you’ve resolved all the jQuery dependent script issues. Otherwise, you’ll waste a lot of time clearing the caches over and over while you attempt to resolve dependencies.</p><p>I enabled all the recommended options in Super Cache and turned on optimization of HTML, JavaScript, and CSS in Autoptimize and ran another test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*zVdA2PJGWUpMOUmDB8Hcng.jpeg" /></figure><p>Ok, not too bad… definitely getting somewhere, but Google tells me I need to optimize images and <strong>“Eliminate render-blocking JavaScript and CSS in above-the-fold content”</strong>. Even though I’ve got Autoptimize setup to concatenate and minify my JavaScript and CSS, Google isn’t happy about it.</p><p>Fortunately, there’s a setting in Autoptimize to <strong>“Inline and Defer CSS”</strong> that allows you to paste in CSS that will be inlined, while the minified CSS gets set to load <em>after </em>the initial page load with a JavaScript callback function. Pretty nifty, but how do you get above-the-fold or critical path CSS anyways?</p><p>I’ll tell you! There are a number of tools out there and <a href="https://medium.com/u/2508e4c7a8ec">Addy Osmani</a> has compiled an excellent list: <a href="https://github.com/addyosmani/critical-path-css-tools"><strong>Critical Path (Above-the-fold) CSS Tools</strong></a>. There are server side tools for Grunt tasks, Chrome bookmarklets, and even an online tool for generating critical path css. However, after trying all of these — and a few that weren’t on the list, I found a tool that does it all with zero configuration at <a href="https://www.sitelocity.com/">https://www.sitelocity.com</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xPijVJDL9iytY1UEpcailA.jpeg" /></figure><p>You just paste in your url and it gives you a minified version of the critical path css, perfect!</p><p>So, I took the result and pasted it (without the &lt;style&gt; tags) into Autoptimize’s Inline and Defer CSS option:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*TP3w194kWa6rz53dNJHKxg.jpeg" /></figure><p>I ran some image optimization using TinyPNG’s <a href="https://wordpress.org/plugins/tiny-compress-images/"><strong>Compress JPEG &amp; PNG Images</strong></a> plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eEGHR_OCGvnO3ndFGEaJ5Q.jpeg" /></figure><p>And tested one more time with PageSpeed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hRsZbnnYJPQrMO_Espu47Q.jpeg" /></figure><p>Hey alright! A passing score! As usual, they’ve recommend optimizing images ad nauseam, but I’m certain that my images are already optimized, so I’ll ignore that instead of optimizing to the point of image degradation.</p><p>In conclusion, it definitely takes some work, but you can optimize just about any site to improve the PageSpeed score using these same techniques. A few other things to note about this process that might be helpful to you:</p><ol><li>Use SVGs instead of images wherever possible.</li><li>Host your fonts locally instead of through Google Fonts or some other service.</li><li>If you’ve got 3rd party scripts, like the Facebook SDK loading, try to limit their use on the home page or else you’ll get the “Leverage Browser Caching” warning from PageSpeed.</li></ol><p>Hopefully, you’ll be well on your way to optimizing your own sites soon! If you have questions or comments about my process or ideas for how to improve page speed that I haven’t mentioned, feel free to add it to the comments or hit me up on Twitter: <a href="https://medium.com/u/3cf5371be3c3">Jason Johnson</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16812e5f1434" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>