Your site's slowdown can be cause by a myriad of things including:
- HTTP Requests
- WordPress Configuration
- Theme
- Plugins
- Page Size, Images, & Videos
- Hosting, Bad architecture or Infrastructure (servers)
The list could go on and on depending on the type of site you are running. Your site's speed could be fantastic but your admin horribly slow. So let's break some these down into some details.
HTTP Requests
When doing a site audit or analysis, one of the first things I check when analyzing a site is the number of HTTP Requests a site is making. With HTTP Requests, the fewer the better your site will perform.
Take my site for example. At the time of writing this article, my site has 47 total HTTP Requests:
- Javascript: 19 (620 KB)
- CSS: 12 (294 KB)
- Images: 9 (6978 KB)
- Font: 4 (105 KB)
- HTML: 3 (72 KB)
Now compare that to some ad-driven sites (speedtest.net has 381 total HTTP Requests), 47 is really good. However, it can be drastically improved with some good workflow(s), combining of files, etc. (which I haven't done on my site yet and probably should). If you dive into it, you will see some files that I do not use at all. If you dive even deeper, you will find some CSS that I do not use at all. So I could reduce my CSS file size by clearing out some of my CSS.
How many HTTP Requests does your site have? You can easily check out yours at Gift Of Speed's HTTP Requests Checker.
WordPress Database & Configuration
There are several things within WordPress that you can configure or add to your functions.php
file to ease and improve the site's performance. These include:
Updates
Many WordPress site owners think that WordPress will take care of itself and never update WordPress or any of the plugins and themes in fear of something breaking, which is extremely valid (and why you should always have a staging site). If you are on a managed WordPress hosting company like WP Engine, then you are pretty much covered. However, if you are on Bluehost or Hostgator, then you need to add the ability for WordPress to update itself automatically.
To configure automatic updates, add one of the following to wp-config.php
:
// Disable automatic updates. define( 'AUTOMATIC_UPDATER_DISABLED', true ); // Enable all core updates. define( 'WP_AUTO_UPDATE_CORE', true ); // Enable only minor core updates. define( 'WP_AUTO_UPDATE_CORE', 'minor' );
Personally, I always use the minor core updates configuration and leave major updates to be done manually as this really could break sites that are using more than a few plugins.
Regardless, all active plugins and themes should be updated, and any minor updates should be applied immediately. Minor updates are any updates where the last number in the version changes. So if your plugin is currently version 1.1.2, a minor update would be 1.1.3 or 1.1.4. If your plugin is currently version 1.1, 1.2 could be considered a minor update. Minor updates are usually fixing some small bug or security hole (more below).
While on the subject of auto-updates, auto-updates of translations are enabled by default but can be disabled by adding the following to your functions.php
file:
add_filter( 'auto_update_translation', '__return_false' );
And finally, WordPress sends emails regarding the state of automatic updates. To disable these emails, add the following to your functions.php
file:
add_filter( 'auto_core_update_send_email', '__return_false' );
Comments
Content with lots of discussion can be a huge issue in the site's performance. More advanced configuration would shard comments from the database and host comments in its own instance. However, that is not even a possibility for most of us. Instead, you could use something like Jetpack's comment system or even Disqus, LiveFyre, etc. While I have not done my due diligence on Jetpack's comment system's performance, I have been most satisfied with theirs above the others. Yet, if you lazy load Disqus (e.g., using Disqus Conditional Load), then you can definitely improve the performance of your post page, or any page with comments.
Alternatively, you can break your comment section into pages, which is available by default within WordPress core. To paginate comments, just go to Settings » Discussions and then choose the number of comments you want per page. This should help improve memory consumption and boost page load times for posts and pages with tons of comments.
Finally, removing and preventing spam comments is extremely important. You can easily do this with the Empty Spam button on the Comments admin page.
Revisions
One example is revisions. Your site creates a lot of revisions when you are writing. This will pollute your database and make database queries take longer time to process. To fix this, you can either disable or limit the number of revisions.
To disable revisions, add the following to wp-config.php
:
define( 'WP_POST_REVISIONS', false );
To limit revisions, add the following to wp-config.php
:
define( 'WP_POST_REVISIONS', 3 );
By default, WordPress auto-saves your posts every 60s. You can also slow down how often (in seconds) revisions are taken, add the following to wp-config.php
:
define( 'AUTOSAVE_INTERVAL', 300 );
Personally, I would never turn off autosave because I cannot tell you how many times it has saved me, my friends or my clients.
The Trash
Sometimes, you will have deleted items (e.g., posts, pages, images, comments, links, etc.) that have been placed into the trash. By default, WordPress empties the trash every 30 days. However, you can also configure this by adding the following to wp-config.php
:
define( 'EMPTY_TRASH_DAYS', 14 );
Or you can even disable this (though I highly discourage this as it will bloat your database).
define( 'EMPTY_TRASH_DAYS', 0 );
Database Optimization
Finally, you should optimize your database often. First and foremost, before touching the database, always create a backup. Always! This cannot be over stated. In a subsequent article, I will discuss several plugins that will help you achieve this, but let me give you a high level overview.
Your database should be optimize to remove any unnecessary data such as spam comments, pingbacks, trackbacks, expired transients, and orphaned data (usually from plugins being deactivated. deleted, or removed improperly). Again, before you do any of this, backup your database.
Almost all plugins store something in the database, whether it is in the wp_options
table or custom tables. However, not all plugins have properly implemented an uninstall method to remove the data associated with the plugin (or the plugin forgets about some of the settings it set). So, the WordPress database can accumulate a lot of additional data that is unused.
Now, WordPress does have the ability to repair and optimize itself. You can read more about this in the Automatic Database Optimizing within WordPress.org. To enable this, add the following to wp-config.php
:
define( 'WP_ALLOW_REPAIR', true );
Then you can go to the repair page (/wp-admin/maint/repair.php
) to use the optimization tool.
My favorite and go to plugin is the Advanced Database Cleaner (which has a free version) by Sigma Plugin, but more about that later.
Your WordPress Theme & Performance
WordPress themes are written for a wide audience of people focusing on features, nice and pretty presentations, and flexibility in order to garner sales and revenue. Your theme may be slowing down your WordPress site because the theme is:
Generally speaking, WordPress themes (or child themes) do not focus on performance per se (e.g., conditionally outputting files when in use). For example, while Genesis focuses heavily on performance, the child theme that you are using may not focus on performance, and I have seen, even sadly created, some really bad child theme implementations.
Over-Engineered
In the past, ThemeForest themes have been notoriously bad about providing over-engineered, poorly coded, feature-rich themes. These themes are focused on providing as much functionality and as many features as possible in order to sell to the widest audience as possible. However, Evanto has made great efforts of late to begin mitigating some of these issues they had when the site first started, and there are some really good themes in their marketplace. Other private theme shops are also extremely bad about this (but I am not going to call any of these out explicitly).
One example is shortcodes. Shortocdes are often include as a part of a theme to provide additional functionality, but often theme developers assume that you are going to use them and output the JavaScript and CSS assets without outputting them conditionally (e.g., using has_shortcode
on the post's content).
Not Updated
Your site should be using a child theme, or provide a mechanism for you to customize the site without your site breaking due to a theme update.
Automatic updates can be configured for themes. To add support for automatic theme updates, add the folllowing to your functions.php
file:
add_filter( 'auto_update_theme', '__return_true' );
Or if you want to prevent automatic updates, then add:
add_filter( 'auto_update_theme', '__return_false' );
Alternatively, you can also have finer control over what theme(s) you may want to auto-update.
add_filter( 'auto_update_theme', 'prefix_auto_update_genesis', 10, 2 ); /** * Auto update specific theme. * * @param bool $update Whether to allow auto-update. * @param string $item Item slug. * * @return bool Whether to update plugin. */ function prefix_auto_update_genesis( $update, $item ) { if ( 'genesis' === $item->theme ) { return true; } else { return $update; // Else, use the normal API response to decide whether to update or not } }
Fonts
Some themes will output several Google Fonts in all its font weights and styles but you may only use a subset. For example, if you were to select all styles and weights for the popular Open Sans, even Google tells you that it will have a slow load time.
The Plugins You Use & Performance
WordPress plugins are also written for a wide audience of people focusing on features and flexibility. The best plugins focus on a single feature and/or problem. Please note, it is not the number of plugins being used, but the quality of the plugins (see this article). However, many WordPress (non-performance) plugins also do not consider performance. The biggest culprit and example are slider and gallery plugins. Both Soliloquy and Envira Gallery entered the market and took its marketshare entirely based on its performance capabilities.
Your site could be slow because you have plugins that may:
- Duplicate functionality
- Not used
- Use too much CPU and Memory (RAM)
- Be old and out-of-date
- Pirated
- Poorly coded
Duplicate Functionality Plugins
We all use WordPress plugins to enhance our site(s). However, sometimes we use plugins that duplicate functionality that our theme has or even another plugin! Recently, I was working on site that had not one or two but three different slider plugins installed! That was the first thing that had to go! Another example is that we have plugins that we are using that your host may provide out of the box (e.g., No Revisions, Force Strong Passwords, etc. are some plugins that WP Engine already helps on their managed hosting).
Let me given you a couple really good and easy examples. First, many of us love icons, and if you look at many WordPress sites, you will find Dashicons and Font Awesome in the HTML but only one of them is used (except when the user is logged into the site and admin bar is showing). This is often because one will be outputted by the theme and the other will be outputted by a plugin. There are many reasons why this happens but is something that we all need to be aware.
Second, we all need good SEO and sitemaps. But you do not need Google XML Sitemaps if you are running Yoast's WordPress SEO plugin or his premium plugin.
Unused Plugins
Many people stop using a plugin but are afraid to deactivate the plugin because "it may be in use somewhere on the site." These excess plugins may be causing performance and/or security issues on your site that you are not even aware.
High CPU/Memory Plugins
Some plugins are detrimental to your site's performance because they require heavy CPU or memory (RAM) to run. This could be due to the plugin's code and/or use. WP Engine maintains a phenomenal (and dynamic) list of Disallowed Plugins, note especially the Related Posts Plugins, Broken Link Checker Plugins, and Email Plugins. One other is WordFence, which is a great security plugin but does affect performance.
These aren't bad plugins. They provide functionality that you may want or even need, but they are performance hogs preventing your site from performing its best. If you "need" any of these plugins, you may need to upgrade to a VPS or Dedicated Hosting plan (see below).
Old Plugins
All active plugins should be updated, and any minor updates should be applied immediately. Minor updates are any updates where the last number in the version changes. So if your plugin is currently version 1.1.2, a minor update would be 1.1.3 or 1.1.4. If your plugin is currently version 1.1, 1.2 could be considered a minor update. Minor updates are usually fixing some small bug or security hole. So always keep your plugins up-to-date!
Automatic updates can be configured for plugins. To add support for automaticplugin updates, add the folllowing to your functions.php
file:
add_filter( 'auto_update_plugin', '__return_true' );
Or if you want to prevent automatic updates, then add:
add_filter( 'auto_update_plugin', '__return_false' );
Alternatively, you can also have finer control over what plugins you may want to auto-update.
add_filter( 'auto_update_plugin', 'prefix_auto_update_specific_plugins', 10, 2 ); /** * Auto update specific plugins. * * @param bool $update Whether to allow auto-update. * @param string $item Item slug. * * @return bool Whether to update plugin. */ function prefix_auto_update_specific_plugins ( $update, $item ) { // Array of plugin slugs to always auto-update $plugins = array ( 'akismet', 'buddypress', ); if ( in_array( $item->slug, $plugins ) ) { return true; // Always update plugins in this array } else { return $update; // Else, use the normal API response to decide whether to update or not } }
Pirated Plugins
Face it. Some people hate paying for WordPress plugins. After all GPL means free, right? Wrong. GPL means that the code can be freely distributed but does not mean that the plugin itself is free. Developers provide a service above and beyond the plugin. They provide updates and fixes as WordPress continues to evolve. They provide support in helping identify plugin conflicts with other plugins, etc. But regardless, some people still download premium plugins from non-reputable sites. These sites can and often do inject some "phone home" or other malware. Just remember, there is no honor among thieves. If you do take this risk, Sucuri is a great premium plugin to use to watch your site's malware issues.
Poorly Coded Plugins
Like themes, not all plugins are created equal. Some are quick proof0-of-concepts to see if it can make money. Some are quickly done for clients to get the client off the developer's back. Some are coded by junior developers that do things "weirdly," or don't follow PHP/JavaScript coding best practices. Some are written by new WordPress developers (though they may be senior PHP/JavaScript developers or senior other-CMS developers) and just don't know how to code for WordPress, so they do not use WordPress best practices (e.g., not using WordPress's built-in JavaScript libraries).
Also, one of the best practices of figuring out what is causing your site slowness is to deactivate plugins one by one to see which one is causing said issue. So, when you add a new plugin, test your site thoroughly to make sure there are no ill effects.
Page Size, Images, & Videos
Page size is incredibly important. For example a light weight page of 929KB (average web page size in 2011) will always load faster than the average website page of 2-3MB (average web page size today) which will always load faster than the outrageously heavy pages of 30MB (for more information see SpeedCurve's post). The majority of new internet users are in regions where 2G is the basic internet connection. They also are paying for the data they use by the GB or even MB (how much does my site cost the user?). So in order to be fiscally and data responsible, we need to optimize our site the best we can.
Heavy pages are almost always caused by ads, images and videos.The performance of both images and video can be easily improved through lazy loading.
Images are a fantastic way to engage users and prettify your site. However, many sites are heavy laden with tons of images that are not optimized. As a result, the reverse affect could be happening. Instead of engaging your users, you may be annoying your users. To prevent this, I recommend that you optimize your web images whether that is via the command line, some optimization program, or image editing software (e.g., PhotoShop, etc.).
Optimizing an image includes two things: (1.) image height and width and (2.) image file size. The height and width will affect your image file size. For example, if your site is designed to only be 1280px wide, your images don't need to be larger than 1280px wide. Of course there are reasons why you may want to offer larger image sizes but these sizes should be loaded on a user action (e.g., click for a modal or download).
You can resize your images using Bulk Resize, which allows you to resize images without uploading them! This program will also optimize your image approximately 20%. WordPress also attempts to optimize your JPEG images to ~80% quality. However, this too can be changed to improve the quality (e.g., 90%, which improves the files size) or reduce the quality (e.g., 70%, which reduces the file size).
// Increase quality and image file size. add_filter( 'jpeg_quality', create_function( '', 'return 90;' ) ); // Reduce quality and image file size. add_filter( 'jpeg_quality', create_function( '', 'return 100;' ) );
Videos, in my opinion (from a user perspective), should never autoplay. From an advertiser/media company perspective, autoplay does provide some revenue potential, if properly pre-rolled (or even post-rolled). Also, videos should never be played from WordPress. Instead, use Vimeo or YouTube. Both of them have the ability to make the videos private and able to play only on certain domains.
Hosting, Architecture, & Infrastructure
Hosting is one of the biggest culprits of why your site is slow. However, this can only be determined by the process of eliminating all other issues. The primary indicator for determining that it is the host's performance is Time to First Byte (TTFB). Usually with many hosting companies like Hostgator or Bluehost, you have options like:
What is the difference between these?
Shared & WordPress Hosting
Shared Hosting is a web hosting environment that is shared across multiple customers/accounts and websites from a single server. Shared hosting are servers than generally can run any type of website, whether it is written in PHP (like WordPress, Drupal, Joomla, etc.), nodejs, GoLang, Ruby, Python, etc. While many hosting companies have explicit clauses against running Minecraft or gaming servers on shared hosting, some people still do this.
Let me give you an example. Let's say a server can hold and run 100 websites, and let's say a customer has an average of 2.5 websites. This means that a company will place 40 customers (100 sites/2.5 sites per customer) on that server. So if the customers on that server average 5 websites per customer then the server will under perform. Or, say the server is perfectly allocated among all the customers, if any one of those customers begin to spam or send out a plethora of emails, this will affect your site's performance. If any of those customers get hacked, besides being potentially hacked (though most hosting companies have decent isolation between customers), your site's performance will wane due to their hacking.
Now, most of these web hosting companies have monitoring, algorithms, scripts to prevent this from happening as much as possible. However, these monitoring tools, etc. are designed to maximize the use of the server, not your specific site's performance. So if your site's performance begins to slow because of shared hosting, you can ask your host to investigate.
At some point, the only way to improve your site's performance will be to move away from a shared hosting environment to a VPS or dedicated hosting environment.
WordPress Hosting is only another flavor of shared hosting except that these servers are often tuned specifically for WordPress. This means that support for other languages is often removed (though not always). WordPress Hosting at companies like Hostgator or Bluehost is very inexpensive and a great solution for low traffic websites or a proof-of-concept site.
VPS Hosting
Virtual Private Server (VPS) Hosting is a website hosting environment that dedicates a specific amount of resources (e.g., RAM, CPU, Bandwidth, Storage, etc.) to your account. This is one step above shared hosting, which does not guarantee any specific amount of resources to your account, and one step below dedicated hosting. Within the datacenter, a VPS hosted account will receive a single virtual private server, but the physical server may have multiple VPS accounts on it with its resources split among the accounts appropriately.
Let me give you a basic example. Let's say a physical server has 16 CPU Cores and 64GB RAM, and the VPS company offers VPS solutions of
- 4 Cores & 8GB RAM,
- 8 Cores & 16GB RAM,
- 8 Cores & 32GB RAM, and
- 16 Cores & 32GB RAM
Now, the hosting company can host:
- four clients who select option #1,
- 2 clients who select option #2,
- 1 client who selects option #2 and 1 client who selects option #3,
- 2 clients who select option #3,
- 1 client who selects option #3.
Generally speaking, there are two types of VPS Hosts: managed and semi/un-managed. Managed means that you will be given admin portal(s), some automated solutions (e.g., backups) and support to help you do what you need. Semi/Un-managed simply means that you are given the VPS with access and can do whatever you want. While support is given to unmanaged solutions, often it is limited for a variety of good reasons.
At some point, the only way to improve your site's performance will be to move away from both a shared hosting environment and a VPS hosting environment to a dedicated hosting environment.
Dedicated Hosting
Dedicated Hosting is a website hosting environment on a dedicated server for your account. This means that only you and your website(s) are on this server. These servers are much faster because you are not sharing anything with anyone, so all the server's resources are yours entirely. With dedicated, you also get full control of everything, which is both good and bad. As Uncle Ben says, "With great power comes great responsibility."
Reseller Hosting
Reseller Hosting, depending on the company, is a VPS or Dedicated Hosting account for a company or agency to host (and bill) their clients without the overhead of server maintenance, server software, etc. It white labels the true, underlying hosting company. So say you are hosting with a Web Development Agency name WP Awesome Hosts. WP Awesome Hosts could be using Hostgator, Bluehost, Amazon, KnownHost, or any other cloud hosting company (with real data centers) white labeling it as though they are a true hosting company.
Summary
So what is causing your site slowdown? Is it:
- HTTP Requests
- WordPress Configuration
- Theme
- Plugins
- Page Size, Images, & Videos
- Hosting, Bad architecture or Infrastructure (servers)
In the next few posts, I will be diving further into WordPress performance and even more specifics around tooling and identifying performance bottlenecks and issues. Stay tuned!