Website Speed Matters and How to Make it Work for You

04/07/2014 03:07 pm ET | Updated Jun 07, 2014

Although this is not meant as a follow-up of my recent article on - how to protect yourself from sudden traffic spikes, they both share similar mentality, and put together can drastically increase your websites loading times.

The best way to go about this is by determining what are the crucial factors of connecting to a website,

  • Internet Connection: this is all about you, and it will not be possible of you to make something go quicker than it is intended to, although I do believe that in modern times - everyone has access to decent quality broadband.
  • Hosting Provider: a lot of the connectivity and speed of your website is going to depend on the choice of your hosting provider. you should always try to cater to the majority of your website visitors, and choose location closest to them.

Now, all of that is very traditional and makes perfect sense, but the best way of really tweaking your website and optimizing it for the best possible performance, all of that happens on the inside. Happily, over the time of webs development - we've been blessed with a lot of tools and platforms that can help us take our loading times to the next level.

I'd like to take a look at two solutions in this article, which are:

  • Simple Optimization Tips
  • Alternative PHP Cache
  • EXTRA: Tiny intro to mod_pagespeed


I think the best way to go about this, is to begin with the simple tips for optimizing your performance, please make sure you go trough the list with full attention, as there might be things you've managed to skip when doing the initial optimization for website speed, if any at all.

Website speed is actually one of the most trending web design topics this year, and I have a really good feeling that we're going to see a lot of improvement in this area, especially in the way we serve content to our visitors.

Simple Optimization Tips

  • Your images should be optimized by default, minified to the smallest of size, or until the quality persists.
  • Make sure that your images are always resized proportionally, and don't need to be resized by the browser. This can cause a lot of lag spikes.
  • Figure out whether you need to use as many images on any page as you're currently using. Not everything has to be an image, and one good image can replace ten bad ones.
  • You should use either a static website, or a CDN (as dicussed in the article at the beginning of this column) to improve the overall load times of interactive content.
  • Think about implementing a caching system, like APC or PageSpeed. We're going to be discussing these, so don't worry.
  • Think in terms of less is more, and don't over emphasize the fact that you can afford to have cool gadgets and widgets on your pages, they're often the ones sucking away all the load times.
  • You should be using tools to minify your JavaScript and CSS files.
  • Try and put scripts at the footer section of the site, as not to waste any time loading the actual content you're serving.

Okay, these are the ones that I encounter very frequently, and usually taking care of these points is what takes away a lot of the pressure, and allows me to focus on a lot more technical aspects.

Alternative PHP Cache

We're now going to be taking a look at how to install APC, and how to get it going.

This part is unfortunately going to be useless to you, unless you've got shell command access to your web server, but I do believe that these days it's almost a norm. If you don't, you can check whether APC is installed on your server by saving this following code in a file called APC.CHECK.php :

if(extension_loaded('apc') && ini_get('apc.enabled'))
echo "APC is Working!";

remember to add some PHP tags, and then check whether you've got it or not, and if you don't - your best bet is by contacting the hosting provider directly, and kindly asking them to look into the problem for you.

Installing APC is incredibly easy,

sudo apt-get install php-apc

that's it, you've got a fully functional cache platform on your server, keep in mind that it is configured to be working globally across all of the websites on your server. The next thing we want to do after installing APC is to check whether it is working, and once again - we can use the script I provided above.

In case of it not working, you'll want to open up the php.ini file, which in my case is located at /etc/php5/apache2/php.ini, after you've opened the file, scroll all the way down till the end of the file and add the following configuration options:

; telling php.ini that there is an extension to load
extension =
; total ram storage to allocate to APC
; depends on how much ram your server has got
apc.shm_size = 128
; the below config means that every time you change something, you'll need to clear the cache
apc.stat = 0

these are not the only settings we can work with, but they're the most basic ones to get the cache working for our server. I recommend reading this blog post from Greg Rickaby, he has compiled a really great tutorial that explains a couple of more settings of APC.

Okay, the one last thing that is left to do is build a script that we will use as a way of clearing our cache, do remember than with our current settings - we will need to clear the cache whenever we make a change to any of our PHP files.

Open up code editor, and save the following code snippet as APC.CLEAR.php:

if (function_exists('apc_clear_cache') && $_GET['key'] == 'alex') {
if (apc_clear_cache() && apc_clear_cache('user'))
print 'APC cleared!';
print 'Error?;

} else {
print 'Wrong key!';

You need to replace the word 'alex' with your own key, after you've done that, you can access this file trough:

I think the key adds a nice little touch, and protects you from accidentally clearing the cache at the wrong times, or have someone else do it for you all the time.

EXTRA: Tiny intro to mod_pagespeed

I hope you'll be sticking around for my next column, where I'll be discussing a great speed enhancer module built by Google, it goes by the name of mod_pagespeed and offers extensive features for those who want to increase their overall website performance.

Photo courtesy of Mufidah Kassalias