WordPress is inherently fast, and that’s why so many professional bloggers call it their choice platform.
Like many new bloggers, I used to think that until I had enough traffic to make a difference, I’d worry about the bandwidth and site speed later. But that’s not thinking ahead considering that today social media can drive an overwhelming amount of traffic in a very short period of time; you don’t want to get caught with a crashed site.
When you’re not prepared for lots of traffic, it’s common for a web host to suspend your account temporarily, and that’s something you don’t want. If your writing is decent and you’ve been doing some minimal promotion, then it could happen to you. Think positively and prepare your blog as though it’s going to be a huge success. To do that, here is a tutorial on how to speed up your WordPress site.
Note: As always, with everything, you should backup your WordPress installation before making any code changes.
Utilize WordPress Object Cache
By inserting this simple code into your wp-config.php file, you can set WordPress to begin caching database queries rather than initiating new server requests on each load. You don’t have to understand why this works, it just will.1. Enable the WordPress Object Cache:2. defineENABLE_CACHE, true; on this topic:
By reducing the number of queries, you’ll both increase the speed of your site, and reduce the server resources that are consumed each time you receive a visitor. As a result, you’ll find that it will make your web host much happier in the event of a huge traffic spike.
Utilize a caching plugin
The main plugin that meets this need is the WP Super Cache, which does exactly what it says. It caches posts and stores them as files on the server so that repeated requests are dealt with faster and with fewer resources. The plugin will automatically update as comments are added so the dynamic nature of the blog isn’t lost.
Another option, which is used right here on Mashable, is W3 Total Cache. It’s a plugin that promises 10 times the speed of your site without it.
2. Choose the Right Host
There are several web hosts that are optimized to run WordPress. And while WordPress is not that picky, it does have a set of ideal server settings. Most web hosts meet the basic requirements, but you can find more information about what’s necessary here.
Choosing the right host means more that just buying storage space. Many discount hosts will try to fool you with promises of massive server space at a cheap price because they know you will likely never use the promised enormous allotment. You should really be aware of:
Look for hosts that have more of a commitment to WordPress as a CMS and blogging platform and not just a mention at the bottom of their features list. Another solid resource is the WordPress hosting page.
Also, though most shared hosts will likely be running Apache, keep in mind that WordPress can also run on NGINX, which can increase your server’s speed by changing the structure of the server requests. NGINX powers massive websites like Hulu, SourceForge and WordPress itself.
If these big boys choose NGINX, you know it delivers.
3. Prune Your Plugins
Take a look at your plugin list and remove the inactive ones. Then remove the any actives ones that you don’t actually use; they are likely to place a strain on your serve resources because WordPress loads all plugins when a page loads.
Make sure you’re always running the latest stable release of both WordPress and your plugins. Many older WordPress plugins are not efficient and will weigh your blog down.
WordPress 3.0 comes with a revamped plugin update feature, allowing you to update plugins faster, smoother and easier. It also offers a bulk update feature that is completely new to WordPress, so there’s no excuse for letting your plugin versions expire.
4. Choose the Right Theme
Themes can make or break a WordPress installation. Go for something stylish but simple. It’s important to understand that fewer images will equals less loading time, which means a speedier site. Choose themes with the fewest possible images and a CSS-based design. Themes with tables, frames and static HTML will be slower than those based on the latest technologies. You might want to choose a minimalist theme and modify it to suit your needs.
There are many resources for minimalist themes, including this one Six Revisions and this one at Tripwire Magazine. Don’t just take the theme’s simplicity as a sign of load speed, though; check the actual speed using something like YSlow or Pingdom’s Page Test.
5. Compress Images
While a clean page means speed, you have to balance that with the fact that strong supporting images are key to a successful blog. But there is no reason to sacrifice speed for quality. By ensuring your images are appropriately formatted and compressed, you can help increase your blog’s speed.
The easiest way to remember formatting is like this:
Images that use only a few colors should be saved as .GIF or .PNG files, and images that use a full spectrum of colors like true photographs should be saved as .JPG files. If you use photo editing software, like Photoshop, you can “save for the web,” which will find the best format to save, while still maintaining quality.
Next you should resize images to the smallest possible size to get the job done. When doing so, the color format should be RGB, as indexed images don’t scale well.
When saving, set the total color amount to the smallest value possible without sacrificing quality. A combination of these steps will greatly decrease your image size and therefore your server response time. You should play around a bit to find the right format and experiment when uploading to determine which settings produce the smallest, high-quality image.
6. Compress Your Code
Stylesheets are easy to compress, just use your favorite text editor to delete comments and unnecessary spaces and line breaks. Although you won’t see a drastic difference unless your style sheets involve tens of thousands of lines.
Use CSS Sprites
7. Keep It Local
Don’t rely on other people’s servers to be fast, so minimize any widgets, badges or applications that run off other locations. If possible, try to self-host all images and code, such as your analytics. That said, if you’re posting videos use a service that is built for such a load, like YouTube or Vimeo.
But if you are expecting or receiving lots of traffic, you may want to look at paying for a dedicated server and not trying to host all your projects in that one place alone. A lot of people don’t realize that the geographical distance from a server actually matters. If the vast majority of your traffic comes from a specific country or region, consider locating your hosting close by.
8. Reduce PHP and HTTP Calls
Websites were once built statically, meaning that each page was hand-coded and built from the bottom up. Now, most websites are generated dynamically each time a visitor loads the page, which allows for each experience to be custom designed for each person, making for a richer browsing experience.
In order to accomplish this, many websites use PHP, a scripting language that allows you to reference remote content based on criteria set by the developer. For example, a site might use PHP to determine that this is a first-time visit, and the site may then use this information to generate a welcome message.
Each time one of these PHP “calls” is made, a request is made to the server hosting the website, which takes time usually milliseconds. This time is called “latency,” and some websites have thousands of calls each time the site is loaded, which can translate to millions per day depending on traffic.
Wherever possible, scan your site for PHP requests and replace with static HTML. By doing this, the browser will simply read the HTML as opposed to asking the server what it should display. Here is an example of a slow and fast way to produce the same result:
Slow:<?php bloginfoname; ?><?php bloginfodescription; ?> Fast:<title>Mashable – The Social Media Guide<title>
There’s more you can do to minimize PHP calls. This tutorial will help you cut down the PHP calls that occur in the typical WordPress header. You can also reduce PHP calls by eliminating any logging that might be happening; some advanced plugins offer an option to track plugin activity with a log, which can significantly slow down your WordPress site.
9. Keep Your Code Clean
You can validate your code using the W3C Validator. It might seem snobby to have “standards” on the web, but the truth is, there are standards for a reason. If everyone met the standards, browsers would always know how to display the information they’re given. Use the tool at W3C to validate your code and fix any errors. This can be a painstakingly long process but it’s well worth the end result.
Coding errors will slow your load time, especially if images that are referenced but don’t exist. Use a bug tool like Firebug to identify coding errors and fix them.
10. Database optimization
Using a database administration interface like phpMyAdmin, you can select all tables and click “Repair” and “Optimize,” and scan for outdated tables that weren’t deleted when you removed old plugins.
This plugin will take care of the database optimization while letting you stay out of the database itself. While this other plugin offers automatic optimization which may be better for the hands-off blog author.
11. Adjust Your WordPress Settings
Go easy on the front page
There’s no reason to show 100 posts on the front page, and really, you don’t even need to display the full post content on the front page. You can adjust this setting in the WordPress Dashboard under the Settings > Reading panel.
Turn off inter-blog communication
By default, WordPress interacts with other blogs that are equipped with pingbacks and trackbacks. Every time another blog mentions you, it notifies your site, which in turn updates data on the post. Turning this off will not destroy links to your site, just the setting that generates a lot of work for your site. For more detail, read this explanation of WordPress Pingbacks, Trackbacks and Linkbacks.