99 Ways To Speed Up Your Wordpress Website PDF
99 Ways To Speed Up Your Wordpress Website PDF
web3.com.au
Welcome to 99 ways to speed up your WordPress website!
James Banks
Co-Founder of Web3
Tweet me @_jamesbanks
Deploying your WordPress site on a content delivery network (CDN) is one of the
easiest ways to decrease your website’s load times.
A content delivery network stores the static files of your website (in most cases
CSS & JavaScript) in server located in almost every major capital city around
the world. This means that when a site visitor from say, New York, accesses your
Australian hosted website, the static files are served from the New York CDN
rather then having to travel all the way from Australia.
Check out MaxCDN or Cloudflare to see which CDN best suits your website’s
needs and requirements.
A good caching plugin can do much more than just cache your website to
decrease load times. It is best to review the plugin documentation and install
W3 Total Cache or WP Super Cache. WP Total cache is feature rich and allows
for macro setting changes whereas WP Super Cache is more of a set-and-forget
solution.
The best way to avoid these problems is to invest in a quality dedicated WordPress
web host like WP Engine or Pagely. Investing in proper WordPress hosting can
save you time and money in the long term too. For example, WP Engine hosting
deploys WordPress websites onto MaxCDN and caches it at the same time.
This way you don’t have to worry about doing this each time you launch a new
WordPress website.
If most of your website users are coming from a single geographic region, then
choose a data centre as close as possible to that region. For example, the majority
of Web3’s website traffic comes from Australia, so we use the closest WP Engine
data centre to Australia. This reduces the amount of distance that our website files
need to travel to Australia compared to hosting in USA as an example. This helps
to reduce load times for Australian viewers.
If your website takes longer than 2 seconds to load, and you haven’t actioned steps
1-3 from this book, then your first step is to achieve that. If your website takes
longer than 2 seconds to load, and you have actioned steps 1-3 in this book, then
the following tips should get your website’s load times to less than 1 second.
Pingdom’s Website Speed Test tool is best for basic WordPress performance
optimisation. However, for macro-level performance optimisation WebPagetest is
the go to tool. The information that it provides can be overwhelming to someone
that isn’t web savvy, so best use either tool depending on your skill level.
There are many different online tools that can help you with this. We prefer
Yahoo’s YSlow. Once you have installed YSlow into your preferred web browser,
open up your website and hit the Run Test button.
Once completed, you’ll have a list of suggestions on how to make your website
load faster ranked from A to F. From here, you will want to prioritise fixing the
F-graded suggestions to gain the biggest performance benefits. Work your way
backwards up the alphabet until your have reached your load time goals.
The first step is to find out how many HTTP requests your website is making and
how long they are taking to load. You can use either the timelines page in Chrome
Dev Tools or the Network panel in Firefox’s equivalent version to see what’s called
a ‘waterfall’. The waterfall will show you all the HTTP requests your website is
making and how long they each take to download.
However, be careful when using minifying plugins as they can break your website
by over-optimising files. Make sure that you test and check your website after
installing a minifying plugin to ensure nothing appears broken.
The best way is to ensure that you develop your WordPress websites with high-
performance coding best practices in mind. These best practices are detailed later
in the book.
When dealing with JPG or JPEG image files, you should always apply the 70/35
image compression rule. When saving an image for web in an editing tool like
Photoshop, drop the image quality to 35%. If there’s no noticeable picture quality
loss from the file, save it. If you do see noticeable loss in image quality at 35%,
then increase the quality up to a maximum 70% until there is no noticeable
quality loss. Most images do not degrade at 70% quality. The goal is to strike a
balance between small file size by decreasing image quality without creating an
ugly looking image.
If you are a PC user, then PNGGauntlet is an excellent piece of free software that
removes unneeded image data from your PNGs. This reduces file size without
needing to reduce image quality.
Place all your website’s PNGs into PNGGauntlet, run the program, and replace
the old PNGs with the optimised PNGs to decrease page load times.
Finally, you can change the compression format between Median Cut, Posterizer
& Dithered. You can test to see which settings reduces the file size the most
without noticeable quality loss.
Slider controls or website user-interface controls are common candidates for CSS
sprites. To create your own CSS Sprite, you can use the online tool Sprite Cow.
The tool will generate the CSS Sprite positioning code for your images for you.
If the image has shrunk down from its original dimensions, then you can use
the Media Editor inside WordPress to resize the image. This way, only the actual
size of the image displays on your website, saving file size and reducing page load
time.
As an example, if you know that your blog post feature image size is 400px by
250px, you can specify these dimensions in your functions.php file. This way,
WordPress will handle the image resizing for you. The WordPress Codex outlines
which image types you can specify certain dimensions for. It also outlines a
variety of different hooks you can use in your functions.php file to increase
performance.
Iconslate is an excellent free app that allows you to create a set of web-ready
favicons and touch icons in one click. The app ensures that the icon size is correct
so that your icons are not larger than they need to be.
Iconslate also saves you time with it’s one-click create all feature.
The most common of these are gradients, patterns and shadows. If you are using
these design elements in your website, then you should aim to achieve the design
using CSS3 rather than images. This is because design elements created using
CSS3 do not need to download an image file, which decreases page load times.
There are many online tools, like CSS3 Generator, that can help you create your
own gradients and shadows easily. Follow the prompts to generate your own CSS3
elements by completing all of the requested fields.
The reason why you would do this is because Base64 code string is compatible
with CSS allowing you to remove the additional image download. This allows the
browser to process and render the pattern while the CSS file is being downloaded
compared to downloading an additional image file. Be aware that recreating
images as Base64 code string is only recommended for basic patterns and images.
More complex images can result in a long Base64 code string. This would add a
lot of weight to your style sheet and slow your website down.
IcoMoon is an excellent app that collects the best font icons from around the
world into a single resource. One of the most versatile and flexible icon fonts is
FontAwesome by Dave Gandy. You can download and integrate FontAwesome
from IcoMoon along with many other icon fonts.
The IcoMoon app allows you to select only the font icons that you want to use in
your website, and outputs them in your own custom icon font file. The result is a
smaller icon font file, which helps to decrease page load times.
FontPrep is an awesome Mac app that allows you to remove unneeded characters
from your website’s custom font files. If you do decide to compress your font files,
check each page on your website to ensure there are no text-rendering errors. If
your website’s content changes a lot, it may be better not to remove characters to
reduce the risk of potential errors.
If your web server is not gzipped, then you can apply snippets from the HTML5
Boilerplate’s .htaccess file (details provided in the next few pages) to enable
gzipping on your website’s server. Keep in mind that .htaccess is designed for
Apache servers, so the following tips may not work other types of servers. Also,
you may be able to shortcut some of these tips by completing tip #2.
You can download the HTML5 boilerplate’s .htacces file from Github. Once
downloaded, search the file for the phrase “ | Expires headers ”. Copy and paste
the entire expires headers code snippet into your WordPress .htaccess, and save
the file.
By using the ETAGS snippet, you can force your visitor’s browser to reply on
Cache-Control and Expires Headers. This results in one less step in downloading
your website to view in a browser, which decreases load times. It is best to
check first if your web host applies ETAGS by default as most good web hosting
providers do this.
Vary: Accept-Encoding will allow your web server to send different cached
versions of your website to avoid this problem. Include the code in your .htaccess
file from the HTML5 boilerplate to take advantage of this. Keep in mind that
good web hosts will have already done this for you.
It pays off to review all the classes in your style sheet as you write code. This
ensures that you don’t fall into the trap of repeating code and creating a large code
file size.
Why is that? A tab space counts for 1 byte whereas 4 keyboard spaces (the
equivalent width of a tab space) counts for 4 bytes. This may seem minuscule,
but when you are writing thousands of lines of code, the numbers do add up. The
solution is to make sure that your code files are using tab spacing by using a find
and replace all function. By doing so will remove unnecessary keyboard spaces
and replace them with a single tab space.
Font manipulation is perhaps the most over sighted CSS syntax that is not
shorthanded. The specifiers that can be defined in shorthand are: font-weight,
font-style, font-variant, font-size, line-height & font-family.
Although the elements can be defined in shorthand in any order, the most used
order is: 1.border-width, 2. border-style, 3.border-color.
Just like CSS border elements, there is no particular order that you need to
arrange the elements in shorthand form.
An easy way to remember the syntax order of shorthand margin and padding CSS
is to think of a compass face - north, east, south, west. First position values are
north (top), 2nd is east (right), 3rd is south (bottom) and 4th is west (left).
For example, hex colour values that use six of the same characters (example above
in red), can work with only the first three characters defined (example above
in green). As each character equals one byte, halving the length of solid colour
values can help to reduce the file size of your CSS.
This shorthand way of writing shorthand CSS also applies to padding, margin and
border elements.
When you are writing lots of CSS, it can be easy to forget to write some of your
elements in shorthand. A great tool to check your CSS code, and convert it to the
shorthand format is SHRTHND.
Paste in your CSS code into the left, and the app will output the code in shorthand
format on the right. The app will highlight the code that it has outputting in
shorthand on the left. That way, you know which classes and IDs to replace with
the shorthand code.
Tools like Code Beautifier can automate most this process. It does so by tidying
up your CSS and removing unnecessary weight. You can choose different levels of
compression depending on how much file size you want to reduce. We find that
the tool works best when left set on its standard settings.
The easiest way to remove unnecessary brackets is by doing a find all search.
From here, you can search for any instances of “{}” in your style sheet, and
remove them. The same rule applies for your files that contain HTML However,
the find all search criteria should be “></”.
Although it can be convenient to use HTML tags for spacing, it is better to use a
CSS to space out your elements.
This one class can be reused many times across your web pages. Clumps of
HTML tags need to be added in each time to space out elements. This creates a lot
of unnecessary file weight which decreases load times.
Can I Use is an excellent resource that allows you to see what CSS prefixes are
required to render your CSS3 code in major browsers. It is a good practice to
check this website when writing CSS3. This is to make sure that you are not
including any unnecessary prefixes in your CSS code.
By not including unnecessary weight to your style sheet, you CSS file can load
faster.
If you are creating a website that uses a lot of different prefixes, you should
consider loading them dynamically with -prefix-free. Through a lightweight piece
of JavaScript code, -prefix-free checks what browser you are using, and only loads
the prefixes required for that browser. Your website will load faster as only the
browser-specific prefixes are downloaded, compared to downloading all prefixes
for all browsers.
You should review your style sheet once completed and remove all empty spaces.
Or, if you are a Sublime Text user, you can use a package called ‘Remove Trailing
Space’. This package will automate the process of removing the empty spaces
for you.
The reason why this is bad is each !important tag adds weight to your child
theme’s style sheet that can be avoided. The solution is to make sure that you’re
child theme CSS file is defined after the parent theme’s CSS file. This way, the
child theme CSS will overwrite the parent’s CSS file without needing to use
the !important tag. An even better way would be to ensure your style sheet is
enqueued correctly in the child theme by using this codex code.
SASS and LESS does come with a learning curve. However, if your website does
a lot of CSS based tasks, introducing SASS or LESS can definitely pay off in the
future. Apps like Compass can help you to write quality SASS quicker through its
range of built-in features.
However, using too many font options can have a negative impact on websites
performance. The general rule for performance is to use one or two Google Fonts
at the most on any one website.
Make sure that you only select the font weights that you intend to use on your
website to save unnecessary file size. In general, a normal, italic and bold font
weight suffice for most website designs.
Cufon requires a separate JavaScript file to function. This adds to the load time of
your website. If the font that you want to use is not a Google Font, then you can
use tools like Font Squirrel’s webfont generator. The generator can create @font-
face webfont kits, which are JavaScript free.
The mobile-first approach has many performance advantages over the traditional
desktop-first approach. Designing for a small mobile screen forces you to devoid
of any unnecessary elements. The result is a more focused, simpler and better
performing website. This explanation only scratches the surface of the
mobile-first philosophy. If you are looking for more, check out our presentation
from WordCamp Melbourne 2013.
Building a website with a primary goal in mind helps you to create a focused user-
experience. By removing all the non-essential features, your website will preform
better as it is not weighed down by the stuff that distracts your users from the
website’s primary goal.
If the answer is no, then you should exclude the element. The result will be a more
focused website that is simple for your users to understand what it is about. From
a performance standpoint, less is more. In general, the less amount of individual
elements you have on your website page, the better it performs.
For example, if you’ve ever been on a mobile website, and you’ve seen the desktop
styles load then all a sudden the website’s mobile styles load in. This makes the
website look buggy to the user, and doesn’t set a good first impression. You can
reduce the noticeable impact of the problem by having your mobile CSS load first
before your desktop CSS. See the next page for a working example.
The general rule to follow for performance is to avoid repainting CSS wherever
possible. This is because repainting can be a heavy operation for web browsers
to complete. However, in some cases, repainting CSS is unavoidable. The best
way to avoid repainting is to make use of a theme that well fits the design of your
website. Alternatively, writing your own theme from scratch or from a framework
is another solution.
This results in better website performance. If you use caching on your website,
such as W3 Total Cache, the performance gains are more noticeable.
By doing so can increase the above the fold render time of your website. This
allows your web pages to load faster above the fold which is where your users
attention will be focused on initially. If you are unsure if your website could
benefit from this trick to improve above the fold render time, then you should
run your website through Google’s PageSpeed Insights.
By doing so can increase the above the fold render time of your website. This
allows the part that is first visible on your web page to load quicker. Google’s
PageSpeed Insights will tell you if your website can be better optimised to
improve above the fold render times.
Well coded WordPress themes only download JavaScript on the pages that need
it. However, this isn’t always the case, particularly with older themes. If you are
unsure, then best check your website’s live source code to see which JavaScript
files your website is downloading. If you can see files that render functions
which are not used on your website, then you should deregister them using this
technique. Just make sure to test your website before committing your changes to
a live website.
For example, let’s say you want to use the jQuery UI tabs & accordions on your
website. Common JavaScript libraries will often include script builders. These
allow you to compile your own library including only the two functions that
you intend to use. By including only what you need, you can avoid larger than
necessary JavaScript files. The smaller the file, the less time it takes to download
and render on your website.
However, there is one exception to this rule. If you are using JavaScript to render
functions that appear before your website’s content, load it in your website’s
header.
As an example, the function above in red requires 4 DOM lookups to trigger all
functions. The example in orange only requires 1 DOM lookup as the jQuery
object saves as a variable. The example in green shows a shorthanded version of
the example in orange. This example is smaller in file size, which makes it better
for performance.
For example, the code above shows two ways that you can enqueue the
‘magnificipopup’ script. The example in red loads the script across all pages on
your website, regardless if they are using the scripts functions or not. The example
in green uses checks to see if the shortcode that contains the function of the script
is being on the page first. If it is, then the script is loaded in. This way is more
beneficial to performance as the script only needs to be downloaded if it is being
used.
The code in the top half of the images shows CSS written inline with the
Javascript variable. The better way of doing this is shown in the code example at
the bottom. Here, the CSS is added to the “h1” element by giving it a class, which
is faster to process.
The exception to this rule is if you are wanting to create complex animations
beyond these four attributes. CSS is limited in the complexity of the animations
that it can support. In cases where complex animations are required, the only
option is to create the animations in JavaScript.
The general rule when working with JavaScript and jQuery is to code all functions
in JavaScript if possible. This is because JavaScript is native to most modern
browsers. So, if your jQuery code can function when written in JavaScript, you
will increase your website’s performance as the jQuery library doesn’t have to be
downloaded. If you are not sure if your jQuery functions can be replaced with
JavaScript code, check out the website You Might Not Need jQuery.
Using jQuery libaries outside of the default jQuery library that ships with
WordPress can lead to unpredictable results. With that said, it is best to test
throughly to catch any bugs should you choose to use Zepto with WordPress.
If you do choose to use Closure Compiler, make sure to test your compressed
JavaScript before you deploy it live. We’ve found that Closure Compiler can
over compress the JavaScript code in some cases. This can break the JavaScript
function on your website, causing problems for your users. Regardless,
compressing your JavaScript is an excellent way to increase your website’s
performance that is quick and easy to do.
CSS media queries is lighter in weight and better performing option compared to
JavaScript. CSS media queries do not require additional HTTP requests to work,
making it the better preforming option of the two.
When you enqueue a library to your website, check to see if they have an option
for synchronous or asynchronous downloading. Unless you have specific
development requirements, you should always go with the asynchronous
downloading option.
If the same file is enqueued within your functions.php file, it can download as
soon as your website begins to load. This removes the need to have your child
theme’s CSS file downloaded first.
The result is decreased load time of your website’s external files, which helps to
decrease the load times of your web pages.
Instead of using the default version of Modernizr, use the builder to only call
on the functions you use. This helps to reduce the file size of Modernizr, which
results in the file loading faster.
By telling the browser what the character set is, it does not need to spend further
resources to complete this task. For WordPress websites, use the line: <?php (
bloginfo( ‘charset’ ) );?> at top of your header.php file. Although a small win, this
can help to increase your website’s performance.
The solution is to offload the function to a web application that isn’t hosted in the
same server that your website is. In the case of checking your website for broken
links, this exact function can be achieved with an online tool like Online Broken
Link Checker. Because the function is being processed on the web application’s
server and not your own, your website does not receive any performance
penalties as the function is being executed.
By doing so, your website will perform better as non-essential functions are not
taking away from your server’s resources. Additionally, your website will need less
maintenance and upkeep.
For plugins that deliver advanced functionality to your website, keep them as
plugins. This way, you can ensure that your website can remain scalable and
modular in nature.
If you do come across a plugin that uses encrypted code, see if you can replace it
with a plugin that achieves the same function without encrypting its code.
If you are using related post plugins, either consider removing them or replacing
them with the web services listed on tip #79.
The six web services listed above processes the related post functionality on their
own servers. By doing so, your website will not receive any negative performance
penalties from serving dynamic content through this method.
You can follow the steps here on how to integrate FeedBurner into your
WordPress website.
The WordPress core team and most good plugin authors continue to remove
deprecations while optimising the scripts to increase performance. Keeping
your WordPress website up to date means you can take advantage of these
optimisations to help increase your website’s performance.
Thus, to decrease load time of your website’s pages, only apply HTTPS to pages
that need encryption.
If you decide to integrate Lazy Load to your WordPress website, then use
Unveil.js. As it is a more light-weight version of original Lazy Load, using
Unveil.js can further decrease your website’s load times.
Depending on how you deploy your video on your website will determine what is
the best settings to optimise your video files. We’ve found that in general a bitrate
of 1000 is a good balance between performance and quality. Keep in mind that
the lower the bitrate and size of your video, the lower quality it will be. The best
way to find the right balance between quality and file size is to tweak the settings
until you are happy with the results.
Lower quality creates a smaller file which means it can load faster. However, you
do not what to have your video quality so low that it annoys your viewers and
cheapens the look of your website.
Audio files bitrate can reduce to 128 or 64 without any major losses to audio
quality. This is dependent on the quality of the audio gear used to record the file.
Wistia is one of the many great video hosting services out there that works well
with WordPress websites. By offloading the bandwidth load to a server other than
the one hosting your website, you can increase performance of your website.
However, flat design is not a one size fits all design solution for every website.
All great web designers should understand the context of the design first before
deciding on which style of design best communicates the context of the subject.
Additionally, keeping your design consistent across your website helps to create a
professional and cleaner look and feel. Mixing design styles together often results
in a confusing user-experience with low aesthetic appeal.
To keep your website performing at its best as it evolves, sometimes the best thing
you can do is rewrite the code again. This way, you can write all the code while
factoring the best practices for performance. Considering the rate of evolution
in web design and just how fast a brand new website can start looking outdated,
overhauling your website’s design and code together each year is a great idea to
keep your website performing well.
If you do not have enough time to optimise all the pages in your website, then you
should focus the pages that draw 80% of your traffic. If you are unsure what these
pages are, check Behavior Flow from within your Google Analytics account.
If your website is not accessed on older browsers, then you should consider
dropping outdated browser support and focus on optimising your website for
modern browsers. You can see what browsers your website’s viewers are using
from your Google Analytics account. With new versions of Internet Explorer now
supporting automatic updates, and with the usage statistics of pre-IE9 browsers
decreasing, backwards compatibility to old browser versions will soon not be
necessary for most websites.
With more features comes more scripts, more libraries, more plugins and more
code. When the majority of these features are not being used, bloated themes can
have a big impact on overall website performance. The solution is to deregister
and remove the features that you are not using (see tip #57), or build using a
lightweight framework so you can include only what you need.
If you have the time, building your website from a lightweight framework is a
much superior alternative. This way, you can only include what features you
need and make sure that the code is kept tight and void of bloat. One of the best
WordPress Frameworks for raw performance is Genesis by StudioPress. Genesis
has been well-coded to include many of the performance tips outlined in this
book out of the box.
If you’re not a developer, but want a professional WordPress website that loads
fast, then you should check out Websites by Web3. Let us take care of all coding to
ensure that it can be built to perform from the ground up.
I am confident that all these 99 tips can get your website to load in under 1
second. It’s been a lot of fun writing these tips down, and I hope that you can
apply them and reap the performance rewards. If you have any tips, feedback or
questions, please feel free to reach out to me on Twitter.