menu-icons

WordPress by itself in an excellent CMS, but once you start adding themes and plugins, loading speeds usually start to suffer. On average, if a site loads in under 2 seconds the bounce rate is only 9%, but as soon as load speeds reach 5+ seconds, that bounce rates jumps up to 38%. This is even more important today because almost 50% of internet traffic in North America comes from mobile. Even with 5G, mobile load speeds are still significantly slower compared to desktops, especially in areas where cell towers are further apart.

Why is WordPress slow?

It all comes to do HTTP requests: how many, how big, and how fast does the server respond to them. Each time a page wants to display an HTML file, style sheet, JavaScript or image, it needs an additional request. You can see this in real time by looking at the network tab in developer tools. The average WordPress theme has plenty of HTTP requests, and on top of that plugins bring many of their own. Some light plugins are not so bad, but many have multiple style sheets, JavaScripts and sometimes even their own images. It only takes a few of these plugins to take a site from 20 HTTP requests to 80. Keep in mind that external CSS and JavaScript files are usually small, but they prevent other content from rendering by default. Even if it only takes 0.1 seconds to load each one, with 30 of these that’s 3 seconds, combined with headers and images the total load time will be 5-6, at which point more than 50% of new user traffic is gone.

Solutions

Unfortunately, most of the answers to these loading speed issues, are more plugins. One can play around with all the cache and CDN plugins they want, but improvements will be minimal. The most effective way to drop those load speeds is by reducing the total number of HTTP requests, reducing image file sizes, and moving your WP installation to a dedicated or VP server.

Reducing HTTP requests

Plugins

One of the most effective ways to reduce HTTP requests is by removing as many plugins as possible and simply adding the desired functions into your functions.php file. Plugins are additional PHP functions at their very core, which means anything that a plugin can do, can be coded directly into your theme. The average WP site has 20-30 plugins, and some have more than 50. If each of those loads just one CSS or JS file, that 20-50 additional requests just on load. Many plugins load more than one external file. There may be one or two plugins that you absolutely need, but definitely not 30. The easiest ones to replace are menu and contact form plugins. PHP mail functions are relatively simple and the amount of code required to send it, even with all the proper filters, is small. After all desired PHP code has been added, all required JavaScript and styles can be added to the general theme JS and CSS files.

Default WP Filters

WordPress loads default PHP scripts on the back-end, along with JavaScript and CSS files on the front-end. PHP scripts are all loaded as one HTTP request because it’s done server side. Problem with the front-end JS and CSS is they’re loaded as external scripts, resulting in an additional HTTP request with every file. Many of these are small jQuery files that offer very little functionality, but still take up a request. These files are initiated by default-filters.php in the wp-includes folder. There are several ways to disable this behavior:

Migrating to a Dedicated/VPS Hosting Environment

Shared vs. VPS/Dedicated

Shared hosting is attractive because of cost and convenience, as they’re cheap and you don’t have to worry about troubleshooting if things go wrong. However, those are pretty much the only benefits. The problem with shared environments is that everything is running on the same operating system, and if something goes wrong, it will affect everyone on that server. For example: if another user gets a sudden surge in HTTP requests for one reason or another, this will directly impact your website, since server resources are shared with no real caps. If you’ve ever seen the message “Error establishing a database connection” while hosting on a shared environment, this may be the cause. On top of that, shared servers are constantly dealing with more requests because they’re catering to hundreds, sometimes even thousands of clients. This makes processing times slower for each individual account.

With Virtual Private Servers, each account gets their own operating system. Even though resources are still technically shared from the same server farm, there is a cap on each account and their OS is independent. This means if you hit that cap only your VPS suffers, without affecting anyone else. This is also important when it comes to security since a breach into one VPS will not affect another, even if they do share hardware.

Dedicated servers are the way to go if you want to be truly independent, but they’re the most expensive as well. You get your own hardware and OS. Having a dedicated server is pretty much like having your own computer. In fact, an experienced developer can actually turn their home computer into a server. For those who choose this option: make sure to ask your developer to automate as many tasks as possible, typically called cron jobs. This will make managing that server much easier and reduce the need for tech support.

Nginx vs. Apache

Many WordPress installations are still running on outdated server setups. A great example is how many installations are still running Apache when Nginx has 3x time the processing power. To put things in perspective: Apache servers can only process 3,000 requests per second, while Nginx can do as many as 10,000. This is just the tip of the iceberg when it comes to the advantages of Nginx vs Apache.

Comments are closed.