How To Speed Up Your WordPress Website's Load Time

Andy Forsberg
11 Jan 2022
5 min read

This blog loads faster than 97% of all websites tested by Pingdom's Website Speed Test as you can see in the report above. It wasn't just naturally this fast, it took some effort. To save you time and help you speed up your WordPress site, I've outlined 19 specific ways you can do this on any WordPress driven web site. Some of these items will not be options if your web host doesn't accommodate them, but most of them will be relevant regardless of your web host.

Best Practices for Load Time Optimization

  1. Use the fastest WordPress hosting
  2. Everything on this list is essentially pointless if you're on a bad WordPress web host, so make damn sure you're not! For cheap and fast go with SiteGround. For the fastest go with WP Engine.
  3. Remove Unused Stylesheets & Scripts
  4. If you're not using it, remove it.
  5. Remove Unused Images Referenced via Stylesheets
  6. Don't reference what you don't use.
  7. Disable Unused Plugins
  8. Make sure you're only running plugins you actually use or they'll clog up your site for no good reason.
  9. Ensure Elements Load Only When In Use
  10. For example, don't load a script in your header file throughout your site if it only needs to be called on one page.
  11. Use JPG's Instead of PNG's when Appropriate
  12. JPG's have smaller file sizes, if you don't need the image to be transparent, then you don't need it to be a PNG.
  13. Don't Rely on Slow Third Parties
  14. Twitter is notorious for downtime and slow connections, cache their data, don't depend on it being available all the time or it will destroy your site's load time.
  15. Localize External Files Whenever Possible
  16. Don't make external requests when you don't have to; the more you make, the more servers you have to trust to not slow your web site down.
  17. Load All Stylesheets in the Head Before scripts where possible
  18. JavaScript generally takes longer to load than stylesheets, you don't want your JavaScript to delay the loading of your styles.

WordPress Plugins for Load Time Optimization

  1. Use WP Super Cache
  2. While this may be less popular than W3 Total Cache, I have found it to reduce load time more effectively. You'll just have to deal with a less user-friendly interface to take advantage of it.
  3. Use Better WP Minify
  4. Sometimes it's better not to minify your files, so test the load time with Pingdom's Website speed test before and after enabling it, to determine whether or not it makes sense for your site. This is particularly true if you have a lot of CSS files being loaded, as one big group they can take a lot longer to load than they would separately.
  5. Use WP
  6. Ideally you'll be able to just bulk "smush" all your images. Yahoo's service tends to be a bit unreliable however. If it's not working at the time, you can always run a GTmetrix report on your site and manually download the compressed version of the images it reports as not being optimized.

Third-Party Services for Load Time Optimization

  1. Use a Content Delivery Network
  2. I recommend either Cloudflare - Click here for my setup guide or MaxCDN - Click here for my setup guide
  3. Why use a CDN on your Blog?
    A CDN (content distribution network) is useful for speeding up your website's load time for your visitors, particularly users located far from your website's server's physical site. What it does is store your images, JavaScript & CSS files on locations throughout the world so they load faster via the closest POP (point of presence) site. This also helps reduce the amount of bandwidth your server uses. CDN service is relatively inexpensive with MaxCDN and free with Cloudflare and adds a lot of value, plus it's easy to do, so why not do it? Anyone that takes their website seriously should use a CDN.
  4. Use CSS Sprites (create them with SpriteMe)
  5. This gem makes it super easy to create & implement CSS sprites for your site.

.htaccess Tweaks for Load Time Optimization

  1. Enable mod_deflate
  2. After enabling mod_deflate on your server, add the following directives to your .htaccess file:
  3. # MOD_DEFLATE #<IfModule mod_deflate.c>#The following line is enough for .js and .cssAddOutputFilter DEFLATE js css#The following line also enables compression by file content type, for the following list of Content-Type:sAddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml#The following lines are to avoid bugs with some browsersBrowserMatch ^Mozilla/4 gzip-only-text/htmlBrowserMatch ^Mozilla/4.0[678] no-gzipBrowserMatch bMSIE !no-gzip !gzip-only-text/html# MOD_DEFLATE #
  4. Enable mod_headers
  5. After enabling mod_headers on your server, specify a vary: accept-encoding header by adding the following directives to your .htaccess file:
  6. # MOD_HEADERS #<IfModule mod_headers.c><filesmatch ".(js|css|xml|gz)$">Header append Vary: Accept-Encoding# MOD_HEADERS #
  7. Set Cache Expiration
  8. Add the following directives to your .htaccess file (with whatever expiration you feel is most appropriate for your site of course):
  9. # CACHE EXPIRATION #ExpiresActive OnExpiresByType image/jpg "access plus 1 month"ExpiresByType image/jpeg "access plus 1 month"ExpiresByType image/gif "access plus 1 month"ExpiresByType image/png "access plus 1 month"ExpiresByType image/ico "access plus 1 month"ExpiresByType text/css "access plus 1 month"ExpiresByType application/javascript "access plus 1 month"ExpiresByType application/pdf "access plus 1 month"ExpiresDefault "access plus 1 week"# CACHE EXPIRATION #

WordPress Functions for Load Time Optimization

  1. Load JavaScript from Your Template's Footer
  2. You can install the Scripts To Footer WordPress Plugin...or just add it's PHP code to your functions.php file:
  3. /* Plugin Name: JavaScript to Footer Plugin URI: Description: This plugin automatically moves JavaScript code to page footer, speeding up page loading time. Version: 0.4.1 Author: Vladimir Prelovac Author URI: */// super easy way to move javascript to footer remove_action('wp_head', 'wp_print_scripts'); remove_action('wp_head', 'wp_print_head_scripts', 9); remove_action('wp_head', 'wp_enqueue_scripts', 1); add_action('wp_footer', 'wp_print_scripts', 5); add_action('wp_footer', 'wp_enqueue_scripts', 5); add_action('wp_footer', 'wp_print_head_scripts', 5);

The problem is, some of your JavaScript files may not work properly if they're moved to the footer. In this case you'll have to move the JavaScript files to the footer on a case-by-case basis. You can do this utilizing the wp_register_script() & wp_enqueue_script() functions. These are normally found in the functions.php file of your WordPress theme. The fifth parameter in each function is $in_footer. As long as you set this parameter to true for both functions for a given script, the given script will then be loaded in the footer where the wp_footer() function is called in your theme's template.

For example if you had the script prettyphoto being included as follows:

    wp_register_script( 'prettyphoto', $uri.'/js/prettyPhoto/js/jquery.prettyPhoto.js', array('jquery') );wp_enqueue_script( 'prettyphoto' );

You would adjust it as follows to get it to load in the footer:

    wp_register_script( 'prettyphoto', $uri.'/js/prettyPhoto/js/jquery.prettyPhoto.js', array('jquery'), '', true );wp_enqueue_script( 'prettyphoto', '', '', '', true );
  1. Remove Query Strings from Static Stylesheets & Scripts
  2. Add the following to your functions.php file to remove them from all your scripts & styles:
  3. /* Remove unnecessary query tags from scripts & stylesheets in header */ function _remove_script_version( $src ){ $parts = explode( '?', $src ); return $parts[0]; } add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Use the following instead if you need to keep the version query string on a style or script for some reason (i.e. the Google Maps API reference breaks if it's removed):

    /* Remove unnecessary query tags from scripts & stylesheets in header */ function _remove_script_version( $src ){ $parts = explode( '?', $src ); //return str_replace("","", $parts[0]); return str_replace("","", $parts[0]); } add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Share Your Results

Test your load time before following this guide. Once you have fully implemented these techniques, please share your results in the comments! Also, if you have any further recommendations I'd love to hear those too!

Share this post

Get the Latest Updates

Get notified via email when I post new content.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.