Make Your Site Blazing Fast: Part 2
Last week, I talked about how to speed your site up with a focus on the front-end performance. And while that can be extremely helpful for speeding up your site, don’t forget – there’s the back-end performance too! If you’re still looking for some speed improvements, consider these aspects of your back-end performance.
Whereas on the front-end you can make use of fancy techniques to make your site seem like it loads fast, we’re not so fortunate on the back-end. A server is either fast or it’s not. Server-side logic is either high performance or it’s not. Thus, it’s critical that your site gets to the browser as quickly as possible, which can be accomplished first and foremost by getting on a quality host.
Dedicated WordPress Hosts
There are a host of managed WordPress hosts (pun intended). What managed hosts typically provide is a dedicated VPS (virtual private server), a caching layer, and other infrastructural bonuses that set them apart from your typical shared hosting. These all matter when it comes to loading your site fast, so the best (and first step) to a performant WordPress site should be the host.
For example, let’s take a look at us, WP Engine! We’re a managed WordPress host, and our infrastructure is designed so your sites never touch another customer’s. Compared to a host that crams as many sites as possible on the same server, having your site on a server by itself works magic for speed, as all of that box’s resources are working just for you.
There are many things you can do from a theme development perspective to make your back-end as performant as possible. Nasty loops that do tons of comparisons and use lots of memory (if, if, if, else, if, else, so on) can definitely slow down the loading of a page, as all that logic takes time. There are lots of articles on performant PHP, but I’ll just say to take care in writing your theme logic!
One thing that has saved me from a logic intensive loop taking forever to load is the Transients API. WordPress transients store cached data in the database temporarily, which means your logic only has to run once (whenever the first visitor loads the page) and then the results of that are stored in the database. The Codex has good documentation on the usage of transients, as well as a host of other articles found with a Google search.
Caching assets is one of the best ways to improve performance. Once a user loads your site the first time, you can take advantage of browser capabilities to cache the contents of that site locally, so on the next visit the user already has them loaded. The most common way to cache with WordPress is by using the W3 Total Cache plugin. This plugin (or one similar) is needed on most hosts, except for WordPress specific hosts like WP Engine, who handle caching for you behind the scenes!
Gzip is a file format that’s used to compress other files together, similar to the standard zipping of files. Gzipping allows files to be sent over the web at a compressed size. Once a browser receives gzipped data, it simply unzips it to get the source data. Gzipping is super important for speed, as it sends your data over the wire in much smaller packages (50 – 70% smaller, in fact). Smaller file size equals faster load times!
You should always check with your host to see if Gzipping is enabled on your server or not. If it’s not, modification of your .htaccess file is needed. Again, WordPress specific hosts like WP Engine enable Gzip compression by default, so it’s one less thing to worry about!
A content delivery network (or CDN) is a network of servers that serves up your website and its assets from different locations based on the user’s location. For example, let’s say you’re not using a CDN and your site is hosted in San Francisco. When someone from, say, Spain visits your site, they have to retrieve all your assets from your server in San Francisco. The long distance between the two locations clearly takes longer than if someone from San Francisco loads your site that’s hosted in San Francisco. What a CDN does is serve your assets from, for example, New York, Seattle, Omaha, France, London, Beijing AND San Francisco (and many more). The idea is that users will hit the server closest to them and not sacrifice load time because there’s a huge distance between them and the server.
Some of the most popular CDNs include Amazon Web Services, CloudFlare and MaxCDN. Most of them have free plans, but if you pull a lot of visitors and have lots of assets, you’re most likely going to be paying for a CDN. CDNs are typically easy to set up.
If you make these improvements to your back-end performance (and the improvements to your front-end performance), your site will be blazing fast in no time!