How to optimize Web Vitals on WordPress in 2021
Speed of sites on wordpress is one of the weak side of wordpress, because default wordpress cache system is very simple and not effective. But power of wordpress is in it’s community and number of awesome free plugins. Today I will tell you how you can get A grade on gtmetrix, google page speed, increase your page speed. These rules are working great in 95% of cases and don’t require too much actions from your side and you don’t need to buy extra plugins.
How to test speed of site
Currently, there are two basic instruments which I use to test speed of site.
To give you some inspiration what we made with our theme’s perfomance improvements and 3 years of speed test study
But I want to tell you that score – is just score, you should think about the speed of the site and how your site is comfortable for users, which are more important than just numbers on score. Of course, if you have a very low score, it means that something is not good on your site. Maybe not optimized theme, plugins, hosting, or content. But as you see, even top sites sometimes don’t care about speed and makes more attention to usability.
Also, some users send me their links and ask why they can’t get good speed on site. There are few things which can make any site very slow and it’s not possible to optimize them.
First of all, I want to tell you that if you have slow hosting you can’t get good speed for your site even you are a magic master of caching. How to check your hosting? I want to give you advice. Go to your admin panel of wordpress and activate default theme and deactivate all plugins except required plugins. If it loads not quickly – you need to change your hosting or update hosting plan.
Also, sometimes, it’s important to have server location close to your destination. For example, if site is for USA, make sure that your server is located near USA (or in USA). Because I have some cases, when hosting is good, but because of it’s location, it works very slow in my country. In the end of article we can give you some hosting scores and recommendations.
Avoid external scripts
Here is important thing – external scripts. My head is exploded sometimes when I check some sites. 5 different ads scripts, 3 different statistic and metrics, several notificators like Onesignal, and several external share scripts.
You must know one thing – external scripts are not possible to cache or optimize, so, you can’t have a good score for such sites. Try to find balance, don’t use several statistic plugins, don’t use external share scripts.
And the last thing to check on your site is a number of modules that you use on-site and the number of plugins.
I found that many our theme’s buyers install ALL plugins at once. They don’t know what plugins do and still install them just because they can be useful in future. Why? Don’t do this. Keep active only those plugins that you really know and which you really use on site. Delete all others. Also, don’t try to use too much blocks on Page and too many widgets on one page. We leave in the world which is overloaded with information. Don’t do this also on your pages. Keep everything as clean as possible.
If you place 500 products on the homepage doesn’t mean that the user will scroll through all of them. Check sites like Amazon, Etsy. They have millions of products, but only 4-6 blocks on the homepage. Don’t overload your users, show them only those blocks which can be useful for them.
Setup database and file cache with cache plugins
I think I tried near 10 different cache plugins for wordpress. Some of them were awesome in past, but now is outdated. Currently, I think that most stable plugin is. Wp Super cache. It’s free and easy to setup. I never touch any configurations, usually, I just install and activate cache in settings. Of course, there are many other plugins. I like W3 Total cache, but it can’t be not user-friendly as it has many options which are hard to understand for novices. Wp rocket is very popular among PRO plugins. However, if you don’t know what to choose, use Wp super cache. Also, many popular hosting provide own cache plugins.
Setup for static file cache and minification
WP super cache is plugin for caching database requests but you must also enable file minification. What is this?
Any site on wordpress loads many scripts, because all themes and all plugins can load their styles and scripts for proper work
All of these scripts are separate request in the browser. Most of WordPress sites can have 30-50 requests and this is too high. So, we must merge them into one and optimize such scripts. This is why we need a plugin to Minify and merge them
Previously, I use Better WordPress minify plugin. But it’s outdated and not supported, so, currently, I use Autoptimize or Breeze which have some very important settings which you will need.
I enable second and third option. Second option will merge all files in one file. Third option is important for me. Many plugins and themes use wp_add_inline_script function to add conditional pieces of code on site. I found that if you don’t have enabled the third option, such code will be loaded before other script and drops error. So, I enable this option.
Next options are Css options
Usually, i use two possible set of options. The first one is for removing Render blocking
Take attention on Inline and Defer CSS option – I enabled it when I want to fix Render blocking issue.
How to Eliminate Render Block for styles
This is important especially for google. Because this styles block access to page for google bots in first seconds and bot must spend more sources to load files and analyze page. This is why “Eliminate render blocking” error is marked as First High Priority on all google test tools
We made some experiments. We totally disabled all caching and optimizations on site and checked site without Defer style option in Autoptimize. Here is results
So, we have 30-33 score for perfomance (other scores don’t affect speed)
Now, we enabled Defer and Inline Css option
Immediately, we got + almost 20 points.
Ok, why this option is not so popular on sites and you still see problem? It’s simple. When you enable this option, all styles will be placed in footer. Yes, site will be loaded faster but in few seconds, you will see next problem
Do you see this weird unstyled flashing issue in first second? it’s because the site is loading, but without styles. How to fix this? Well, you can add critical css files in next field.
How to get critical css? There are few methods. You can go to special site place link of your homepage, generate styles and copy them. But this way has one problem – it generates critical css for one page. But your inner pages may have another styles. Autoptimize plugin has support for Paid service critical.css which generates critical css for each page.
Ok. You enabled Defer loading but now you got too low CLS even if you use Critical css option
Starting from November, all test speed tools use Google Lighthouse. And Google reduces score if you have big CLS (Cumulative Layout Shift).
This is the big problem, because ways how we fix Render blocking affect CLS negatively. Let me explain what happens.
When you enable defer parsing for render blocking fix, all your styles go to bottom of page and loaded after page load. This makes part of page as not styled why loading. And this creates layout shift, because elements on loading are shifting after page load. So, fix for one problem creates another problem.
Critical CSS option will reduce layout shifting. But, on our tests, we found that fixing render blocking issue doesn’t improve score and reduces it instead.
So, the only way now is TEST and COMPARE. Enable defer parsing and critical css on site. Check score. Clean cache, disable defer parsing, clean cache again, check score.
By our tests, sites which have large amount of styles (for example, shops, marketplaces, directories) have better score with defer parsing (even if they have not good CLS). But sites which are related only on posts have better score without defer parsing (even if they have notice about render blocking).
After all, here is most stable options for css which we use in our theme and sites.
Eliminate Render Blocking Jquery
As you may know, WordPress loads Jquery library by default as it’s used by many plugins and themes. Bad thing is that it’s loading in header and it blocks rendering. Inside Autoptimize, you can disable jquery from header.
Remove this word from settings
Again, better to test.
Asynchronious script loading
By our tests, we don’t see a big difference in using Async Loading plugin. I just leave a link on the plugin if you want to test.
Problem with Google fonts
There is one more problem which depends on Render block. It’s Font problem. When you load google fonts (which are in use on most of sites), they can block page. Fortunately, Autoptimize has special option to fix this. Find it in Extra tab
Leverage browser caching
Next step is setting correct expiration data for static resources. By default, maybe you don’t need to do this now if you use Autoptimize or good hosting, but if you have such problem in the recommendation on Gtmetrix, here is my special settings for .htaccess
In most cases you have some code in .htaccess which allows wordpress use permalinks. Leave it as is and add such code AFTER existing code in file. This is very important, otherwise, site can be broken.
Copy code from gist and add it in End of htaccess
If you don’t want to edit htaccess, use plugin Speed Up – Browser Caching – plugin, it will make htaccess rules for you.
Clean Assets of site
When we make any theme or plugin, we always keep speed in mind and we always load scripts and styles only when they are needed on page. Unfortunately, this is not what all developers do. We found that almost all plugins load some global styles and scripts on site. Even more, WordPress loads such styles (Gutenberg block styles) on all pages, even on those pages where you don’t use Gutenberg at all. So, we need to clean site from such files. This requires very good knowledge of wordpress, because you can delete something important, however, we can give you some advices what we remove in most of cases, so you can remove such files without problems.
You will need plugin Webcraftic Assets manager or similar which can give option to control assets loading on site.
Once you install plugin, visit your homepage. Click on Asset Manager in admin bar
Page with all files will be opened
Usually, I disable next files
As our theme uses own WOW animation framework, which is working as script, I disable Animation styles of Elementor on whole site
Woocommerce has some Gutenberg blocks, but they are very ugly in design, so, I never use them and disable these files on whole site
If you don’t use Cart of woocommerce, maybe it’s better to disable also wc-cart-fragments and wc-add-to-cart scripts
I also limit two files for WordPress Blocks: wp-embed (responsible for embeding youtube and other services in posts) and wp-block-library. But I do this only for all post types exclude Posts, because i use Gutenberg in posts
Passive event listener issue
This issue is coming from Jquery and some core plugins of wordpress. I tried different plugins to fix issue but they don’t work or break site. Finally, i found that disabling Comment reply in Asset manager usually solve this bug. Comment reply script is required for comments and it allows to show inline form for comment once user click on “Reply” link in comment. If your site doesn’t depend too much on comments or you use Woocommerce (which doesn’t have option to reply in comments), you can disable comment reply
Heavy images is another most common speed problem on sites. Cool full width photos, videos, overlayed images with alpha channel are very popular and they allow to make WOW effect on your site. But in the same time they are very heavy. How to fix this?
When you need images with alpha channel you use PNG format. But WebP is new better format which is recommended by google. We made some tests on our demo and we found that images in WebP format has 6 times less size than the same image in PNG. When you use JPG format, it has no big sense to use WEBP format, but it has sense to change images to webp when you need image with alpha channel.
Currently, wordpress doesn’t allow to upload webp images, so, you must install plugin WP Enable WebP or similar to allow this. You can convert your regular png images to webp images on many sites. My favorite is Ezgif You can even convert video with alpha chanel to webp format (it has sense for small videos, but not for big sized)
This is must have on all sites. Simple script can load images only when visitor scroll to image. This will save tons of traffic and gives you many points on speed test. You can try different plugins for this, for example, BJ lazy load. But we recommend to use themes which have this option in core, because core lazy load is more compatible.
Update. August 2020. From 5.5 version of WordPress, all images have lazy load. It’s working very well under our tests, so, you don’t need to install any additional plugins now
Image optimization in WordPress
It’s always better to load on site only optimized images. If you save them in any photo editor, make sure that you have near 65-70% of output quality. Don’t set 100% quality for photos, users will not see difference but size will be 2-3 times more than 70% quality.
In most of scenarios, you may need to use webp format of image. Looks like it becomes standard of images because it takes 2-3 time less size than other formats.
Do you need CDN?
Gtmetrix recommends you to use CDN. But fact is that CDN just makes more problems than solve them on small and new sites. This is because CDN is a different server than your site, so, again, you can have unexpected delays in image loading, blocking issues, etc
But CDN is must have if you have a really big site with more than 10 000 posts or products, because it allows you to keep your server free from such amount of files. So, my recommendation – use it on sites with big database and ignore it on new sites and small sites
We found that you can save few resources if you deactivate Emodji script and string numeration in files which is enabled by default in WordPress. You can do this in Extra tab in Autoptimize. Don’t use this if you need Emodji or you update site often
Fix Fontawesome and other Icon fonts
Many sites uses icon fonts, like fontawesome. There is one problem with them – Size. It’s really huge file size and google can recommend you to preload fonts. If you see this, you must find links on your fonts and add preload link parameter in header.
Autoptimize has also option to add preload.
If your theme uses any icon font, check it’s size. We were surprised because fontawesome icons have near 1 mb size, when we created custom icons, they have size only 23kb. So, if your theme or plugin uses full fontawesome icon bundle, ask them to replace icons to custom icons.
Elementor Site Kit Fix
Recently we found weird issue on our sites. Even in fact that our theme has optimized font loading, we see that we have several additonal fonts which are loaded on site. After many tests we found that problem is in Elementor. They added new function – Global Site kit, it’s cool feature but way how it’s implemented is absolutely unacceptable. It loads Roboto and Roboto Slab fonts and many colors settings on pages of your site. Problem is that this feature is enabled by default and most of users don’t know about it.
Here how to fix.
Open any of page in Elementor. Then, click on hamburger icon
Then, choose Site settings and Font settings. Click on blue Pencil icon on each font and then, click on Return icon to clean font settings (it’s in Typography line)
Clear all fonts and Update settings.
Elementor dynamic template loading
if your page uses some parts or templates from Elementor, it’s better to load them via ajax, we built special option for this. Watch details how to optimise speed of Elementor templates
Which hostings I can recommend: Siteground, Bluehost, WP engine, Kinsta, WPX. I used these hostings on many sites and they prove me that they are good for WordPress. But here I want to point you to one interesting thing which I found just recently. And this thing is TTFB.
TTFB of Hosting
TTFB is criteria to test speed of hosting. It’s time when the server starts to respond on requests. You can have perfect caching plugin on site, but if your hosting has low TTFB – web vitals score will be bad.
What is range of good TTFB. Well, it’s under 150ms. I tried many hosting and only few of them can provide good TTFB. If you have TTFB more than 500ms on Gtmetrix, maybe, it’s better to move to another hosting.
But I need to make one notice. TTFB is very related to location of server. So, if you have servers in USA and test site from Europe, you can have bad TTFB, but if you try from USA, it can be good enough. This is what I have on Siteground. Here is how to test from different locations – register on gtmetrix.com, now, when you start new test, click on next option and find several locations. So, if your site is for USA users, your servers are in USA location and TTFB is less than 150ms – it’s good enough. You should think about server changing if it’s more than 500ms.
So, in my tests, I used Block theme and the same demo content on different hosting. I used USA locations on all hostings
Here is my results.
- Siteground – 150ms
- WPX – 80ms
- BlueHost – 90ms
- Rocket.net – 30ms
- Cloudways – 40ms
So, Rocket.net is the best one. Unfortunately, their price plans very ugly and very limited in number of sites and traffic per each plan. So, currently I can recommend Cloudways Hosting has some option to choose Server provider. I tried 3: Linode, Vultr, AWS. And for me, best TTFB was on AWS. Especially, it’s great because this server is autoscalable. You can downgrade or upgrade at any time. This is very useful if you have e-shop, because usually each shop can have highly increased traffic on holidays and sale days.
By the way, with this new hosting, I made 100 score on my complex page with videos, Lottie, animations, sliders.
Send us a link, we will give you recommendations to get a high score for free.
These are the main things that you can do with site. Usually, after all steps you will get A grade. Of course, there are many possible reasons why you can’t get it and they are individual for each site. If you want – you can hire me to check your settings and optimize your site.
These methods are good for most hostings, shared and VPS. If you have a high load project, you maybe need some another method with server optimization. For example, settings for Nginx + Memcache.