WordPress website optimization for Google PageSpeed

Site loading speed is one of the search engine ranking factors.

You can check how fast your website is using Google PageSpeed Insights.

Good download speed - if the site is in the green zone.

How to improve the performance of site loading in Google PageSpeed

Error "Defer offscreen images"

Google recommends using the lazy loading principle for hidden images after all important resources are loaded. Install the Lazy Load Optomizer plugin, which adds a lazy load image for Thumbnails and standard WordPress galleries, as well as images of products and WooCommerce product categories.

Error - "Serve static assets with an efficient cache policy"

To correct this error, you need to insert the following code into the .htaccess file (located in the root directory of WordPress, you can still access it using the Yoast SEO plugin):

# BEGIN EXPIRES 
<IfModule mod_expires.c>
ExpiresActive On 
ExpiresDefault "access plus 6 month"
ExpiresByType text/css "access plus 6 month" 
ExpiresByType text/plain "access plus 6 month"
ExpiresByType image/gif "access plus 6 month"
ExpiresByType image/png "access plus 6 month" 
ExpiresByType image/jpeg "access plus 6 month" 
ExpiresByType application/x-javascript "access plus 6 month"
ExpiresByType application/javascript "access plus 6 month"
ExpiresByType application/x-icon "access plus 6 month" 
</IfModule>  
# END EXPIRES

 

If you use Google Analytics, then this error will not be fixed completely. But that's okay, because Google Analytics does not slow down your site.

Errors - "Eliminate render-blocking resources", "Defer unused CSS"

These errors will help fix the plugin Autoptimize. In the settings include:

  • Optimize HTML code
  • Optimize javascript code
  • Optimize CSS code

Check the setting "Inline all CSS".

Also, this problem may occur if the site uses Google fonts. Click on the "Advanced" tab of this plugin. There you need to set the setting for Google fonts - Combine and preload in head (fonts load late, but not are render-blocking).

Error - "Efficiently encode images"

To optimize images, install the WP Smush plugin. This plugin optimizes all images uploaded to the WordPress Media Library. If there are images downloaded from the theme directory, they will have to be optimized manually.

Error "Reduce server response times (TTFB)"

Most often with it helps to fight plugin WP Super Cashe. After installation, you need to enable caching in the plugin settings and enable the option - "Compress pages so they’re served more quickly to visitors. (Recommended)":

If this does not help, it is worth thinking about changing the hosting to a better one.

Error "Enable text compression"

Add to the .htaccess file:

<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript
</ifModule>

Additionally

A snippet that will add asynchronous loading for scripts connected via wp_enqueue_script ():

add_filter('script_loader_tag', 'add_async_attribute', 10, 2);

function add_async_attribute($tag, $handle)
{
    if(!is_admin()){
        if ('jquery-core' == $handle) {
            return $tag;
        }
        return str_replace(' src', ' defer src', $tag);
    }else{
        return $tag;
    }
}

Updated: 21.01.2019

Did this article help you? Rate it!
(1 votes, average: 5.00 out of 5)
Loading...


Leave a Reply

Your email address will not be published. Required fields are marked *