How to Speed Up and Optimize WordPress

WordPress, as a platform, is extremely well coded. However, some people mess their WordPress installations up by installing tons of low-quality plugins, choosing an awful web host, and filling their site with heaps of garbage.

Even if you don’t do something as stupid as these with your site, there’s still a lot of room for improvement when it comes to speeding up your WordPress site. Here are a few ways (some well-known, some not) you can improve the performance of your WordPress sites:

#1: Choose A Good Web Host

You can think of optimizing your WordPress site only after you surely know that it’s not your host that’s slowing down your site. Recently, I’ve been optimizing a site which was hosted on GoDaddy, which is, of course, one of the most horrible hosts out there that puts thousands of sites on a single shared server. As a result, their servers are damn slow. You have to make sure you don’t make these mistakes while choosing a web host that most beginners make.

If you wish to receive WordPress-specific support from your host, you can try a managed WordPress host. WPEngine is a fast growing reputable host that specialises in WordPress hosting. In addition, you can also see the articles in category “Hosting Reviews” of us. Surely you will choose a best hosting provider yourself.

#2: Use A Fast WordPress Theme/Framework

You need to start with a fast and well-coded WordPress theme or framework. If you choose a theme packed with lots of additional features that you don’t need, it’ll negatively impact your site performance.

Choose a fast WordPress Framework or Theme

Choose a fast WordPress Framework or Theme

The default WordPress themes are incredibly well-coded, light-weight, very fast and easily customizable. If you can handle a little bit of code or hire a developer, choose one of those to build something great on top of them. I tweaked the default WordPress Twenty Thirteen theme for some my sites and it’s getting the job done very well.

When it comes to WordPress theme frameworks, there are two opposing giants which cannot be overlooked. Genesis, and Thesis. It’s slightly unfair to equate Genesis and Thesis as two frameworks which are aimed at the same user type -simply because they arent.

Genesis is the perfect theme framework for users who want a highly professional looking WordPress website, without having to get down and dirty with the coding and development aspect of web design.

Thesis on the other hand, would be the choice of the web developer. There would be a long learning curve for the everyday blogger or website owner, but that same level of complexity is precisely what web developers are looking to experiment with. The Thesis developers tool box which comes with the Thesis Professional package would only sweeten the deal.

If it’s simplicity you’re chasing, opt for Genesis. If you want an endless digital playground to build a truly unique website, Thesis is your best bet. This site (haloseeker.com) use Genesis Framework with News Child Theme.

Additionally, you can choose other premium wordpress themes at ThemeForest where has thousands of wordpress developers. They designed and published millions of wordpress themes here.

#3: Install A Caching Plugin

The second most effective way (the first being choosing a good web host) to improve your site’s load times is to install a caching plugin. As soon as you install a plugin like W3 Total Cache or WP Super Cache, you’ll be able to tell that your site loads faster.

In simple words, when a caching plugin is active on your site, it servers users cached copies of your pages. It greatly reduces MySQL database access, no. of PHP requests, server access for static resources, and even HTTP requests (in case of combining multiple files into one).

Wordpress Caching Plugins

WordPress Caching Plugins

W3 Total Cache is one my most favourite WordPress plugins. It offers a variety of caching features:

  • Page Cache
  • Minify
  • Object Cache
  • Database Cache
  • Browser Cache
  • CDN

Initially, you don’t want everything enabled. You can still safely enable everything except Minify and CDN (unless you want to use a CDN).

Minify breaks some other heavily JS-based plugins unless you specifically tweak it. On the other hand, you should tweak the Browser Cache settings to utilise the full potential of browser caching.

W3 Total Cache Config

W3 Total Cache Config

You generally want to enable all those in the ‘Browser Cache’ section for all common file types.

W3 Total Cache Expires Header

W3 Total Cache Expires Header

The value of ‘expires header lifetime’ for different file types should be as high as possible. 604,800 seconds = 1 week

#4: Try A CDN

Offloading the static resources of your site, like images, scripts, css files, can speed up your site. Not only those resources will load faster for visitors, if you use a CDN, your primary server will have less load to handle and thus will deliver significantly better performance while serving the rest of your site.

Generally, those static resources will be served to your visitors by the server closest to them. That will ensure the heavy part of your site loads as fast as possible for your users.

There are quite a few Content Delivery Networks out there. But one that’s really easy to setup on WordPress sites is MaxCDN. I’ve been using MaxCDN since the beginning of this year and it has helped us shed around 2 seconds off our load time.

Use W3 Total Cache plugin with MaxCDN

Use W3 Total Cache plugin with MaxCDN

You can also set it up within 5 minutes using a caching plugin like W3 Total Cache.

#5: Enable Gzip Compression

You should serve compressed versions of your site to your visitors, as they’ll be less in size and will generally load a lot faster.

The best option is to enable Gzip compression straight from cPanel (if your host offers you that) if you’re on a shared server. Otherwise, you can enable Gzip compression using a plugin like W3 Total Cache.

There are also a few tweaks that allow you to enable it from your .htaccess file. You can simply add this code to the beginning of your .htaccess file to enable server-level Gzip compression for a few known file types:

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png

Or use WP HTTP Compression Plugin.

#6: Install Well-coded Plugins

There are literally tons of plugins available for WordPress. That doesn’t mean all of them are well-coded. You should always install plugins that are well optimized for the latest version of WordPress which don’t slow your site down.

You should perform some research before installing a below 3-star rated plugin. Often the plugin will turn out to be poorly developed, using inappropriate hooks. It will not only slow down your site, but in a certain cases might also mess up with the functionalities of other plugins and WordPress itself.

Once in a while, monitor your plugins’ performance and impact on your site’s load time by using a plugin like Plugin Performance Profiler. It isn’t 100% accurate but you can observe the trends to know which plugins are really slow and troublesome for your site.

#7: Maintain Your Plugins

Plugin maintenance is very important for WordPress sites. If you don’t keep all your plugins and WordPress itself updated, chances are that your site will get hacked.

It isn’t a rule, but older versions of plugins are generally more vulnerable to attacks. Not only that, newer versions of plugins are in most cases more optimized, faster, and more secure with less or no bugs.

You should also disable, and even delete the plugins that you don’t use. More plugins doesn’t necessarily mean a slower site, but lots of low quality plugins together will slow down your site significantly.

#8: Optimize Your Database

Optimize WordPress MySQL Database

Optimize WordPress MySQL Database

You can optimize your WordPress MySQL database directly from PHPMyAdmin, or by using a plugin like WP-Optimize or WP-DBManager.

These plugins are capable of deleting all your pending spam comments, trashed posts, auto-saved drafts, post revisions to name a few. They can also perform general MySQL database optimization queries without you having to access PHPMyAdmin.

A well optimized, fast responding database is a huge bonus for a database-driven software like WordPress.

#9: Optimize Uploaded Images

Images are one of the heavier elements of your site. There are a few ways you can optimize your uploaded images.

First of all, you should specify the maximum image dimensions for thumbnail, medium, and large sized images. That means, if you upload an image 1024px wide, and your content area is only 650px wide, normally the image will be scaled down using CSS. When you specify the maximum width of your ‘large’ images as 650px, it’ll then display the pre-resized, 650px wide image, which will be significantly smaller in size.

The second thing you’d want to do is to reduce the sizes of your uploaded images without resizing them, or messing with their quality. Yahoo’s Smush.it is your ally in this case. It is able to losslessly reduce image sizes.

And I quote from the official site: “Smush.it uses optimization techniques specific to image format to remove unnecessary bytes from image files. It is a “lossless” tool, which means it optimizes the images without changing their look or visual quality”.

Fortunately for you, you don’t need to visit the Smush.it website everytime you need to compress a couple of images. There’s a WordPress plugin for that! 🙂

The WP Smush.it plugin allows you to upload images normally while it automatically optimizes them using Yahoo’s Smush.it API behind the scenes.

#10: Replace PHP with HTML Wherever Possible in Your Code

Unless you know what you’re doing, don’t try this on a serious site.

Plain and simple HTML is a lot faster to process for web servers than PHP. If you have a preliminary knowledge about both PHP and HTML, you can replace a few instances of PHP in your site’s code (in themes or plugins) with plain HTML.

I always recommend choosing something (to replace) that doesn’t usually gets changed, such as the URL to your favicon, or your site’s name, or your theme’s stylesheet URL.

For example, in many themes, functions like these are executed for each page load:

<title><?php bloginfo('name'); ?> - <?php bloginfo('description');?></title>
<link rel="shorcut icon" type="image/x-ico" href="<?php bloginfo('template_url'); ?>/images/favicon.ico" />
<link rel="stylesheet" type="text/css" media="screen" href="<?php bloginfo('stylesheet_url'); ?>"/>
<link rel="stylesheet" type="text/css" media="print" href="<?php bloginfo('template_url'); ?>/print.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="<?php bloginfo('rss_url'); ?>" />

And when you replace the bold PHP functions with simple HTML, it looks like this:

<title>HaloSeeker - Blog Tips, Tutorials and Internet Marketing to Make Money Online</title>
<link rel="shorcut icon" type="image/x-ico" href="https://haloseeker.com/wp-content/themes/haloseeker/images/favicon.ico" />
<link rel="stylesheet" type="text/css" media="screen" href="https://haloseeker.com/wp-content/themes/haloseeker/style.css"/>
<link rel="stylesheet" type="text/css" media="print" href="https://haloseeker.com/wp-content/themes/haloseeker/print.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://haloseeker.com/feed/rss/" />

Plain HTML is around 20-times faster than PHP. A simple way to replace such PHP executions with HTML is to open your site (the page you want to hard-code HTML for) in a normal browser and right-click and click on ‘view source’. You can simply copy the entire HTML of a portion of your site’s code and replace the PHP in your theme with that. Use your judgement to determine which PHP commands are responsible for which HTML output.

#11: Delete Old Post Revisions

Do you really need 10s of revisions of your old posts that have already been published a long time ago? You probably don’t.

Open wp-config.php located in your WordPress root directory and add the following code:

define('AUTOSAVE_INTERVAL', 300 ); // seconds
define('WP_POST_REVISIONS', false );

This code will disable all future revisions to be saved and it will also increase your autosave interval from 60 seconds to 300 seconds, so it means your post will be autosaving every 5 minute instead of every minute.

The above code, will not delete your past revisions that are already saved in your database. To delete all previous revisions, you will need to visit PHPMyAdmin and run the following SQL query.

DELETE FROM wp_posts WHERE post_type = "revision";

This should disable Post revisions and delete all previously saved post revisions stored in your Database.

Or you can use plugin to do that. The Revision Control plugin allows you to remove old post revisions from your WordPress database, making it considerably smaller, and your site slightly faster.

Disclaimer: We are not suggesting that Post Revisions is a bad option. This tutorial is only for those who are in the situation where they need to reduce their database size.

#12: Reduce Spam – Start Using Akismet

Spam comments take up significant space in your database. You should setup the pre-installed Akismet plugin properly to catch those comments and prevent them from going live on your site, and additionally to discourage spammers from posting them in your site in the first place.

Akismet is considered is one of the best anti spam WordPress plugins

Akismet is considered is one of the best anti spam WordPress plugins

Setting up Akismet is pretty simple, in reality. All you need to do is to register for an Akismet API key on the Akismet website using your WordPress.com account.

The next thing you’d want to do with Akismet is checking the box in Akismet settings that says “Auto-delete spam submitted on posts more than a month old”.

Of course, you can manually empty the spam queue anytime from the ‘comments -> spam’ section.

You should read: 5 Best Anti Spam WordPress Plugins For 2014 and Reduce WordPress Comment Spam Without Plugins.

#13: Turn-off Trackbacks & Pingbacks

Trackbacks and Pingbacks aren’t good for your site speed. Whenever someone links to you, a trackback gets created, utilizing server and database resources.

So, unless absolutely necessary (I have no idea why they’d be), you can simply disable trackbacks and pingbacks from WordPress’ Discussion Settings.

Turn-off Trackbacks & Pingbacks

Turn-off Trackbacks & Pingbacks

#14: Use CSS Sprites

Theme images and miscellaneous other small (both in size and dimensions) images should be combined into as few images as possible, using CSS sprites. For example, there are many small images that get loaded on http://www.target.ca/en/ in the logo, footer, social icon images, etc. When you place your mouse cursor over the original images or click them (right click, view image). This how the sprite-main.png of the site looks like:

Sprite Image Main

Sprite Image Main

There’s a lot of (intentionally reserved) blank space on the bottom of the image, but nevertheless, that’s what a CSS sprite image looks like.

The browser gets unique portions of it as individual images using CSS positioning, and loads them on the page in the desired position.

This single image saves me 5 HTTP requests. So creating CSS sprites is worth it. You can even use a drag and drop online tool like SpritePad.

#15: Use A Responsive Design

You can use a responsive theme to load less resources (for example, images) for mobile devices or specify high-resolution images for high-resolution screens. That way, mobile users won’t see heavy images, and desktop users won’t see small, highly-compressed images.

You can specify what to load for what type of users, based on their screen width. There are lots of other important advantages of using a responsive design.

Responsive Design

Responsive Design

And responsive sites are preferred by Google, so you can expect a slight boost in SEO once you switch to a responsive design.

Sites that use responsive web design, i.e. sites that serve all devices on the same set of URLs, with each URL serving the same HTML to all devices and using just CSS to change how the page is rendered on the device. This is Google’s recommended configuration.

#16: CSS in Head, JS in Body

CSS should be loaded in the <head> section as per HTML recommendations. Referencing stylesheets outside of the <head> section will prevent the browser from displaying content as soon as it is loaded.

JavaScript blocks progressive loading as well. When a browser encounters a <script> tag, it tries to interpret the code before loading the rest of the page. This is however not the case with asynchronous scripts, like the usual Google Analytics tracking script, so you don’t need to worry about those scripts. So, you should place most javascripts in the bottom of your code, before the ending </body> tag, instead of the <head> section.

While your page remains as heavy as it originally was, tweaking these little things will make your site seem to load (appear) faster.

I recommend you to use Scripts To Footer Plugin. This small plugin moves scripts to the footer to help speed up page load times, while keeping stylesheets in the header.

#17: Optimize Your Widgets

It’s important that you optimize your widgets to make them as light and easy-to-load as possible. For example, widgets of social networks like Facebook, Twitter and Google+ load external javascripts and often css while being rendered.

If the scripts or css aren’t likely to be updated often, you can upload them directly to your server and serve them from your own server (or your CDN). Not having to rely on external servers, you can improve your site speed by optimizing your widgets.

Conclusion

Slow load times don’t only create a bad impression about your site to your visitors, it’s also bad for your SEO.

You can monitor the current load times of your site by performing Pingdom’s Site Speed Test. A load time of under 3 seconds is decent, under 2 seconds is impressive, and even less is blazing fast!

Website Speed Test

Website Speed Test

You can also find useful information about your site’s current performance and areas in which it can improve by testing your site in Google PageSpeed Insights. Remember, a good PageSpeed score isn’t always the best possible thing for your site, an unbelievably tiny load time is.

What other ways do you recommend for speeding up WordPress sites and improving load times?

Leave a Reply

1 Comment on "How to Speed Up and Optimize WordPress"

Notify of
avatar
Infinity Tricks
Guest

What are the best Caching plugins?

wpDiscuz