Skip to content
OSULZER.AT
SEO20 min read· updated March 2, 2022

Optimize WordPress Load Times with PageSpeed Insights

Page speed is a ranking factor. How I raised a WordPress blog's PageSpeed score from 62 to 93 with W3 Total Cache, lazy loading and image optimization.

This post is from 2019 - some of its content may be outdated by now.

To get your website to good positions in search results, many aspects of the site have to work well together. Informative texts with suitable keywords and high-quality links pointing to your site are especially important. With the ever-growing share of smartphones and tablets used for browsing (at the time of this post, a good 45% of all internet users), the speed of individual pages is becoming more important for search engines like Google as well. Google does not state directly how strongly the speed of a website affects its position in search results, but it is definitely a ranking factor. One indication is, for example, Google’s PageSpeed Insights tool, which was heavily overhauled recently. With this helpful tool you can test your own website and get suggestions for improvement as well. The goal is to make websites faster and leaner at the same time. This lets users with a slow internet connection or a low-powered device jump from page to page quickly anyway.

In this post, we take on a blog that has since been archived and raise its PageSpeed score. The blog is based on WordPress and a custom-developed theme. For the optimization, we use freely available plugins and tools, and we also discuss Google’s own recommendations.

Starting Point

With 62 points, our blog has a score in the lower middle range. So there is plenty of room for improvement, and most likely it can be applied to your blog or website as well.

The first item among Google’s suggested recommendations is to eliminate resources that block or slow down rendering. This refers to stylesheets and JavaScript files that the browser has to download and interpret on every visit. The more files the browser has to retrieve and interpret, the longer it takes until the actual website appears on the user’s screen. An optimal solution here would be to combine all required .CSS and .JS files. WordPress plugins that are used in the frontend of the site have the unpleasant habit of loading their own CSS and JavaScript files. In theory, every installed plugin can slow us down.

A handy plugin for combining JS and CSS files is the free WordPress plugin W3 Total Cache. This caching plugin takes care of several tasks at once that will make our lives noticeably easier.

W3 Total Cache Settings

General Settings

After installing W3 Total Cache, a new tab appears in the admin panel where you can make the basic settings for W3 Total Cache. The caching plugin does not start working automatically after installation. The individual features have to be activated and tested by hand first. Many of the options we go through in this post can cause problems on your website or blog. After activating each option, it is a good idea to test your website to find out whether everything still works as intended.

Page Cache

WordPress creates content anew on every page visit. For every visitor, database queries are sent, for example, to display the information of the requested page. These requests delay page rendering and can quickly lead to bigger problems such as an overloaded database on high-traffic sites. With the Page Cache feature, static versions of the pages are stored and can then be served directly. The available cache methods depend on the features installed on the server. Installations on regular web hosting can in most cases be set to Disk: Enhanced without concern.

Minify

The Minify feature is a very effective way to reduce the size of CSS, HTML, and JavaScript code. CSS code that is loaded split across 4 different files, for example, can be combined into a single file automatically after activation. Four requests to the server become a single one. Unfortunately, this setting often cannot be activated without problems. Especially with several included JavaScript files, compressing and combining them can cause trouble. After activating Minify, you should test all functions of your site. The developer console of your browser can also quickly tell you whether any JavaScript errors occur after the change. Tip: if you have already activated the Page Cache, you have to delete the currently generated cache after every change using the option Performance -> Purge all Caches in the admin bar.

If problems occur after switching to Minify, you can try to make further settings under the menu item Minify. Under JS, you can then define how Minify handles JavaScript files. Among the options is, for example, Operations in areas. Here you can specify how JavaScript files should be included. Make sure that JS code marked with “async”, for example, is not executed at the moment the page is visited. With cookie banners, for example, this means they are no longer displayed. If you run into problems, you can try switching to Combine only. If you use plugins that cause problems after the change, you can look for alternatives that may cope better with the compression. In my experience, problems occur especially with older plugins that have not been updated for some time. If these settings do not lead to the desired result, the last resort is unfortunately to disable JavaScript compression. In my case, the compression is compatible, so I got lucky.

If Minify worked, you can take a look at the source code of the page next. The nicely nested code should have turned into an unreadable stream of HTML. This code is not nice to look at for the human eye, and certainly not clear, but it is no problem for browsers. The saved lines lead to smaller file sizes and faster load times. JavaScript and CSS code have now also been combined into matching files.

Object Cache and Database Cache

For simple blogs, speed should already have increased noticeably through page caching and the changes from Minify. If your WordPress blog also contains database-intensive applications, using the Database Cache feature is recommended. It stores the results of database queries and can then deliver them faster. In addition to the Database Cache, there is also the option to keep the Object Cache implemented in WordPress for a longer time. By default, the cache used by WordPress is rebuilt on every page load. The lifetime of this cache ends when the website has been delivered. The data in the cache is then deleted. W3 Total Cache offers the option to keep this cache longer, which can make recurring script executions noticeably faster and relieves the database further.

Browser Cache

Browser caching is another important tool for optimizing the load time of a WordPress blog. With this feature, content such as JavaScript, CSS, or images is marked with an expiration date. This expiration date tells the visitor’s browser that the marked files do not change regularly and can be stored temporarily. As an example, a visitor comes to a website and loads the stylesheet, JavaScript, the logo, and the HTML code used to display the content. Our site states that the stylesheet, JavaScript, and logo are valid for 30 days. If the visitor then jumps to another subpage, their browser does not request the stylesheet, the already loaded JavaScript code, or the logo from the server again, but accesses them directly from its own cache. The required data does not have to be downloaded again, which saves time and resources.

For browser caching, you will find further options under Browser Cache in the left menu. Under the advanced options, it is a good idea to send an “Expire Header” for the respective file types. This can help convince the visitor’s browser to actually store the marked files in its local cache. To do this, activate the option Set expires header.

If you run into problems with W3 Total Cache, the settings for browser caching can also be made directly in your .htaccess file. To do so, you can insert the following code at the beginning of the file.

# BROWSER CACHING #
ExpiresActive On
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/svg "access 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/xhtml-xml "access 1 month"
ExpiresByType application/javascript "access 1 month" 
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 1 month"
# BROWSER CACHING #

Gzip / Deflate Compression

The browser cache settings also contain another important function for compressing text-based content. If the option Enable HTTP(gzip) compression is activated, the server transmits a compressed version of the content, which the browser then unpacks and displays. You can think of this process like a classic .zip file. It reduces the amount of transferred data and thus enables faster loading, especially on mobile devices with slow internet connections. Images are deliberately not transferred compressed, because common formats such as JPG or PNG are already compressed. Additional compression only puts unnecessary load on server capacity and offers no benefit.

If gzip compression does not work through W3 Total Cache, the matching settings can also be written directly into the .htaccess file. The following code is intended for use on Apache servers. If you use a web hosting package, this applies to you in most cases as well.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-web-app-manifest+json
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/x-component
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/javascript
</IfModule>

Interim Analysis: Noticeably Improved

With W3 Total Cache, we were able to make a broad range of performance improvements. Let us take a quick look at our PageSpeed Insights score.

Our optimizations earned us 24 points, and the load times of the page should already be noticeably faster. We have not quite reached our goal yet, though. There are still a few optimizations, some of which can be implemented fairly quickly.

Lazy Loading

When a visitor finds their way to our website, all content is loaded by default when the page is opened. That includes, for example, images further down the page that are not in the viewer’s field of view. With lazy loading, images that are not essential at first are loaded only shortly before they become visible. This makes page rendering noticeably faster, especially on mobile devices with a slow internet connection. If you care about a spotless W3C validation, you should skip this solution. With lazy loading, images are by default given their own CSS class and lose their “src” attribute, which can cause problems when validating the page. From a search engine optimization standpoint, however, the improved load times weigh significantly more than the underlying code.

For WordPress there are various ready-made plugins that add lazy loading to your blog. I chose BJ Lazy Load. In the settings, you can define which media should be handled by lazy loading. You can also choose to show a placeholder image until the respective resource has finished loading. This small change gives us an even better load time, and Google’s PageSpeed Insights now rates us with the following score.

Interim Analysis: Almost There

A pretty good score, not perfect but still impressive. To get even more points, we have to look at Google’s remaining recommendations.

Properly Size Images

This item shows images that are displayed scaled on the website. For example, it might point out an image with dimensions of 500×500 that is displayed at 250×250 on the website. If you see messages like this, it helps to adjust the size of the thumbnails used. To do this, you have to adjust the thumbnail sizes used by your theme, for example. The options required for this are found in different places depending on the theme. In most cases, the thumbnail settings are located directly in the functions.php file. It is best to search for the function add_image_size. You can find more information on how to use this function in the official WordPress Code Reference.

Eliminate Render-Blocking Resources

Opinions differ on this suggestion. Among other things, Google recommends deferring unused CSS code, or loading it only when it is actually needed on the page. The CSS code that is most important for the page, such as font information, background colors, and other basic style information, should be built directly into the source code. Important JavaScript code should also be moved directly into the source code. JavaScript code that is not required for the actual display of the content can be deferred, for example with the “defer” attribute. JavaScript included with defer is only executed once the website has been loaded completely and interpreted by the browser. Alternatively, the JavaScript code can be moved from the header to the footer area of the website, so it no longer blocks the page load.

If you use several plugins that provide frontend functionality, this type of optimization can be hard to carry out. Many JavaScript functions built into various ready-made themes have to be executed as soon as the website is opened. If you change the point at which JavaScript is loaded, you can end up with display errors or completely missing functions. Implementing the requirements for stylesheets can also be problematic. If the CSS code needed to display the website is loaded too late, display problems can occur. Google recommends placing important CSS code directly in the source code of the page. This means, for example, CSS code that describes the general structure of your page, such as the dimensions of the most important div containers, the chosen font, or the colors to be used.

With Minify, we combined these files earlier and thereby already saved load time. Most plugins do not offer the option to output CSS code inline on the website, and until recently this practice was even prohibited for plugins offered on ThemeForest, for example. This makes implementing this requirement much harder still. This brings us to the question of whether optimizing the stylesheet information really makes sense. Our page does load a few milliseconds faster after the change, but we may have to accept display errors in return. Google’s suggestion to defer unused CSS code is also questionable. It means that we adjust the stylesheet on every page so that it really only describes the elements that are actually visible. That does save traffic, but when visiting further subpages the visitor’s browser cannot fall back on the already cached version of the stylesheet, because it differs from the previous page. The first visit would be a few milliseconds faster, but every further subpage would be a few milliseconds slower.

In many cases, it is not possible to resolve these problems without considerable effort. It is also more than questionable whether this optimization is worth the effort. The time consumed here would almost certainly be better invested in the search for new backlinks.

For those of you who still want to tackle this option, here are a few approaches.

To quickly move scripts to the footer when using W3 Total Cache, you have to edit the footer.php of your theme. One line before

, insert the following HTML comments. In place of the inserted HTML comments, W3 Total Cache will insert the styles and scripts that were scheduled to run in the header, but only in the footer area.

<!-- W3TC-include-js-head -->
<!-- W3TC-include-js-body-start -->
<!-- W3TC-include-js-body-end -->
<!-- W3TC-include-css -->

The name of the tag indicates whether CSS or JS files should be inserted at that spot. After the change, you should test all functions of your site. Also open the developer console and take a look at the Console, where any JavaScript error messages are displayed. To make troubleshooting easier, you can also disable the Minify feature you activated earlier. This way, error messages are attributed to a single JavaScript file, which can then be linked directly to a problematic plugin.

Serve Images in Modern Formats

Not all file formats are ideal for displaying images on the web. PageSpeed Insights has problems with formats such as PNG, especially when they are larger than absolutely necessary. Services like TinyPNG can quickly help here by compressing the files without visible loss. At this point, PageSpeed will most likely also show you that further images can be optimized. WordPress plugins like reSmush.it let you shrink and optimize uploaded images directly. With reSmush.it, you can also optimize all images uploaded so far. The downside of reSmush.it is that images may be 5MB at most. For blogs or websites that use many images, it is a good idea to do the image optimization on your own PC. For Windows, there is the Caesium Image Compressor, which can optimize whole folders of images including subfolders. The tool is free and offers a wealth of possible settings. Apple users have a pretty good alternative in ImageOptim.

For optimizing images on your own PC, it is a good idea to download all images from the wp-uploads folder and then optimize them on your PC. The improved images can then be uploaded again directly. With an installed image optimizer plugin like reSmush.it, all uploaded images are then improved automatically. In most cases, no further work is necessary.

Reduce Server Response Times (TTFB)

TTFB stands for Time To First Byte and indicates how long a visitor has to wait for the first information to be transferred from the server. A website programmed in PHP only sends information to the visitor after the server has finished executing the scripts. For complex websites with many database queries, this process can take a lot of time, so simple blogs already have a noticeable advantage here. Caching should already have reduced this value noticeably. If there are still problems with the server response time after all optimizations, the cause may be the server hosting your WordPress site. Google itself recommends delivery in under 0.2 seconds or 200ms. With regular web hosting in particular, you are one of many customers on the hosting server who want to deliver content. Shared hosting servers can quickly become overloaded, which in turn naturally affects the performance of your site. If all other optimizations fail, often the only option left is to move to another provider or to your own small vServer.

vServer Recommendation

When it comes to vServers, I have had very good experiences with DigitalOcean. The advantage of DigitalOcean is that you pay for so-called droplets, which are essentially small vServers, by usage time. The smallest droplet costs 5 euros per month and can be canceled at any time or upgraded. So if your blog or website suddenly gets more traffic than the current vServer can handle, you can upgrade at the push of a button. The price change takes effect directly after the upgrade. You do not have to worry about topics like a monthly commitment.

A vServer does not provide you with a ready-made admin panel. Instead, you have to get your hands dirty. DigitalOcean maintains a very detailed knowledge base that contains all the important steps for configuring a Linux server and also provides information on security. If you already have trouble administering your own PC, you should prepare for a steep learning curve. Working with Linux and standalone servers is the next logical step for web developers, though. The know-how you gain through administration pays off in the long run and helps you understand the big picture a little better.

You can find more information about DigitalOcean here (affiliate link). If you sign up for a DigitalOcean account through this link, you get a credit of 100 US dollars for a period of 60 days. If you decide on DigitalOcean after this trial period and top up your account, I receive a small “kickback” credited to my DigitalOcean account. This does not cost you anything extra.

Web Hosting Recommendations

If you do not want to take the leap to your own vServer, you can of course also switch your web hosting provider. For sites that are to be hosted in Austria, I can recommend Easyname. The admin panel is well structured and offers all the settings needed to run WordPress. Current PHP versions are usually available quite promptly, there are free certificates from LetsEncrypt, and a dedicated backup space. SSH access is included with a few packages, but unfortunately without root privileges.

More highlights:

Alternative: CDN

A CDN (Content Delivery Network) relieves your own server by delivering static content such as images through other well-connected servers. One of the best-known providers in this category is Cloudflare. A content delivery network makes particular sense for internationally oriented websites. If you already use a standalone server that is slowly reaching its limits, you can relieve it with CDNs like Cloudflare.

Final Scores and Conclusion

After all optimizations, our blog reached a score of 93 (62 at the start). That puts us in the upper range. I deliberately skipped a few optimizations. For example, the stylesheet was not split up or moved to the footer area of the page. With this optimization, the score would probably have ended up somewhere between 95 and 97 points. The effort was simply too high to be justified for a blog in archive mode. In my case, the web hosting used was also fast enough, so it did not justify switching to a standalone vServer.

Fast websites are fun and build trust. Fast load times are especially important if you offer products or services. For online shops in particular, optimizing load times has a directly positive effect on the conversion rate. Another nice side effect is slightly improved positions in search results, especially for mobile devices. In 2019, short load times are an important aspect that should by no means be ignored. Or do you enjoy browsing slow websites?

If you need help with the PageSpeed optimization of your website or online shop, I am happy to help. You can find more on the subpage Search Engine Optimization in Vienna and Lower Austria.

Search Engine Optimization

Get found more easily?

Keywords, technology, and content - SEO from Vienna, with personal support.

See SEO

New project?

Contact.

Tell me briefly about your project - I'll get back to you personally.

Your data is used solely to handle your inquiry. More in the privacy policy.