This is a question we are asked by people on a regular basis: “Why is my website slow?”
The answer provided here, since 2012, is generally speaking in a WordPress context – because we are WP specialists – but a lot of the rules will apply to really any website, particularly one which runs on a Linux, Apache, MySQL (or MariaDB) and PHP setup.
Please leave comments at the end, and remember, we will come back, add, update, and improve this item in future. This is the web, not a newspaper, and everything we do here can be improved. Open Source ftw 🙂
Site speed: why does it matter?
It is something that is becoming increasingly important in this “I want it now” world we live in, too, as people are prepared to wait only fractions of a second to be delivered the content they were looking for – slow websites risk seeing the little “x” hit before they ever get the chance to deliver their message!
Site speed & Google search engine rankings
Worse, search engines like Google know that slow websites are of less interest to the population at large, and so punish them with poor search engine rankings, making your slow website even less likely to reach that Google searcher you wanted to sell your products and services to.
Enough of the why, show me the how!
So what can be done about it? And, why is your website so slow?
Well, the answer is usually a combination of things (isn’t it always!). The main things that a website must do have to be considered. When a browser makes a call for a website, the following things take place (this is simplified!):
What’s happening (slowly!)?
- Browser asks network “what is at this domain address”;
- Network points to DNS server;
- DNS server routes request to web server;
- Web server renders page (if dynamic) and delivers HTML and files back to the browser;
- Information is rendered by user’s browser into the website you see before your eyes.
There are a lot of steps there, yet this can be achieved on websites Silicon Dales have set up in 0.3 seconds. How? By making each step of the way as streamlined as possible.
The simplest way for you to increase the speed of your pageloads is to make sure the file size is as low as possible – the information being transferred will exit your web server and enter your local machine faster if it is small.
Deflate all the things
Use Gzip or mod deflate to shrink HTML, JS, and CSS files.
Minify HTML, JS and CSS
Minify and remove whitespace wherever present to get rid of those unnecessary kilobytes.
Optimize your images
Optimize images with a service like ShortPixel, to make them as small as possible, [and try to serve static content, like images, from a cookieless domain]. 2018 edit, this cookieless domain thing… it isn’t so important.
Choose and use a good CDN for static content
Also serve static files from a CDN (content distribution network) to allow multiple elements to download faster – browsers only download so many items from one location, so get things flying along in parallel by serving images, etc, from another domain.
What the heck is “static content”?!
Static content is the things in your site which are “downloaded” by browsers from files which do not change. Like JPG, GIF or PNG images, for example. Or CSS files or JS files. Ideally, CSS and JS would be combined into one, minified, file, and downloaded once, from a CDN!
Leverage browser caching
The above improvements to offloading static content make the initial pageload nice and zippy, but boy-oh-boy it can be lightening fast if the browser caches all the things in your page (like logos, CSS, JS and etc) for use on subsequent pageloads. Get your .htaccess (or Nginx conf – or even httpd.conf!) files sorted so that browsers can cache all the things, for as long as is sensible.
Upgrade your web hosting server
Make your web server faster – by upgrading it – though this (expensive) resort should be a last one! Almost always, improving your hosting environment will lead to speed improvements.
Move to the latest version of PHP
Here’s a thing. Upgrading PHP to the latest stable version will almost always speed up a PHP site from the previous version. If you are on an unsupported version well, try not to be, and soon.
8.0 is currently the absolute bees knees and cats pyjamas to us (that is a colloquialism meaning really really great 🙂 ).
Not all code will necessarily keep up, though, so you will need to test it before you go. Maybe a plugin is holding you back. Consider ditching that plugin. Seriously. The benefit of updating PHP is worth finding a replacement.
Install a caching plugin
If you are using WordPress, install and configure a good quality caching plugin. There are a few around. We like WP Rocket for ordinary users, though it should be noted a lot of managed WordPress hosts will “roll their own” caching solution. Not all of these are brilliant, in our (considered) view, but they will be better than “no caching at all” which is… slow.
Page caching is built into WordPress, but managing this well is a plugin’s job. Caching basically means saving the page content (in some way) so that is does not need to be pulled out of the database every. Single. Time. The exact same page is loaded.
“Caching is like handing out a business card to people (one you already printed) versus writing down your name and telephone number every time someone asks for it: way way faster!!” Robin Scott 2018
Think about your DNS and name servers – consider CloudFlare
If your visitors come from multiple countries and continents, consider hosting in the cloud, or co-location, to reduce network latency. Name resolution can be slow. If you serve a global audience, consider using a DNS and proxy caching service like CloudFlare to quickly service visitors on the other side of the globe. CloudFlare can also help with traffic spikes, security (a bit), and DDOS protection. Also, if your server does actually flake out, they can serve a cache. Its a nice – free, as in beer – option to quickly improve really any setup.
Further optimizations and deeper gains
There are more steps that can be taken, but once you have done the above, you should notice some improvement. If you have major problems, and the above looks okay, you could have network issues – make sure your DNS is setup correctly, and, if it is, next consider moving hosts. Try something quick and cheap to setup like Amazon’s AWS to test. If your scripts and websites load quickly there, then your hosting could be the culprit.
Get Silicon Dales to Optimize your site!
We take all of the above steps – and more – for our clients, to make sure their mission critical business websites stay online, and render faster than the rest. Contact us today if you’d like Silicon Dales to assist.