Why Your WordPress Website is Slow (and how to fix it)

Slow web server caused by shared Hosting

$6 a month seems like a good deal for full service hosting and it is, except that you are sharing it with a whole suburb of other websites. If your neighbor on your shared hosting gets a spike in traffic, those resources are taken from your bandwidth and make your website slower. This is known as the noisy neighbor. If you get too much traffic to your website while on shared hosting, the hosting company may take your website down because it is taking too many resources from your neighbors. Being on shared hosting also limits your access to the server to only a small partition, making it impossible to configure caching software that requires access to the root of the server (more on this later).

Solution: Get on a VPS (Virtual Private Server)

Get off shared hosting by setting up a virtual private server (VPS). Having a VPS allows you full control of your technology stack, allowing you to configure your operating system, install caching software and choose Nginx as your HTTP web server server (more on caching and Nginx later).

People visiting from different parts of the world have latency from being far from your web server

Visitors from different parts of the world will have latency. If you just have one server on the west coast and someone visits from Europe, milliseconds, although not that much will be lost and the user experience affected. Delivering content quickly is part of the user experience and losing even milliseconds can drastically affect conversion rates with e-commerce and web pages with “call to actions”.

Solution: Use a CDN

Content distribution networks (CDNs), such as MaxCDN and Cloudflare, are third party services that provide servers dedicated to hosting your assets on regional servers spread across the globe. Having your assets hosted on CDNs ensures that your visitors are having the best user experience possible, with the lowest amount of latency possible.

CSS and JavaScript take a long time to load

WordPress can have 20+ CSS and JavaScript dependencies. Typically websites call CSS and JavaScript files from the header or footer with a HTTP request for each file. With WordPress this would be very time consuming when loading a page.

Solution: Use wp_enqueue inside the functions.php to load CSS and JS

Inside of functions.php there is a function called wp_enqueue where you can attach all your CSS and JavaScript files. When WordPress loads a page, wp_enqueue calls all your CSS and JavaScript with one HTTP request. Using wp_enqueue speeds up your CSS and JavaScript load times exponentially by the number of files and scripts your WordPress website has.

With multiple concurrent visitors, Apache web server is slow

Apache HTTP web servers have been the industry standard since 1996. Concurrent connections weren’t really a problem back then since not every Tom, Dick and Harry was on the internet. Now if your website goes viral, you could have 20,000 concurrent visitors. Apache is really bad in this scenario because it creates a new process for each concurrent connection, costing valuable RAM and slowing your page load times drastically.

Solution: Use Nginx instead of Apache

Nginx is 80% faster than Apache at high traffic times. Nginx has an event-driven architecture that keeps a steady asynchronous connection that consumes the same amount of RAM regardless if it’s 2 concurrent connections or 20,000 concurrent connections. For example, if you have 20,000 visitors to your website at one time, Nginx will serve the HTTP request with the same process through an asynchronous connection, instead of creating a new process for each visitor like Apache does.

Requesting dynamic content and assets slows down your server

Each page or post that is visited makes the server, the PHP on the server is then parsed, compiled and executed, and sent back to the browser (or something like that). After that, the assets are requested from the server and sent back to the browser. Upon each visit to a page the process repeats again, even with content that rarely changes and for all intents and purposes is static content.

Solution: Install APC cache and W3 Total Cache Plugin

If you are running on a VPS, you can install software such as APC cache and Varnish HTTP accelerator. APC caches your operation code (opcode) inside your RAM instead of recompiling PHP on every page load. Varnish is a HTTP accelerator. APC along with Varnish can speed up your website by many times.

Solution #2: Use wp_cache functions

If you are experiencing issues with plugins loading multiple expensive SQL queries, use wp_cache to store returned queries in a cache. wp_cache functions require $key and $data to be passed in, while $group and $expire are both optional.

Launch Your Project

Get your project off the ground with Space-Rocket! Fill out the form below to get started.

Space-Rocket pin icon