By Shehzad Azram

 

So you have created a website, you’re very proud of it and can’t wait to show it to your friends. A few months down the line, when it gets popular, you notice that the site is taking longer to load. The answer isn’t always to throw money at additional hardware or RAM. Here are some proactive steps you can take to manage the scalability of your site.

1. Constantly monitor your site(s)
It might sound obvious, but the first step is to use tools that help you monitor your site. Monitis.com is one such tool that sends you a daily response time (i.e.your site loading time), uptime and any failures that have occurred so you can react appropriately. It also lets you see what the loading time is from different parts of the world (although the free version limits this to just the US and Germany).

 

2. Keep things updated
You should keep all of your packages up to date. This will help as the underlying algorithm may have been re-written to be more efficient, or the author may have made other significant changes. For example, by simply updating from PHP 5 to PHP 7 you get almost double the speed. You should also try to look for new packages which may have come into market and could be more efficient than the ones you’re currently using.

If you manage your own server, such as Apache and Linux, it’s important to keep that updated as well as other dependent packages.

Finally, you should get rid of packages/libraries that you don’t need, both on your site and on your server.

 

3. Minimise all your assets
You should minimise all Javascript, CSS files and combine each into one file. With images, consider using image sprites that put all images into one single image. You can also compress your images so they look great at half the size and also try different image types that will reduce their size considerably. All of this helps as your browser needs to make fewer requests to obtain assets, and if these assets don’t change the browser caches them. Minimising all of these files each time you change your code can be a tedious task so you should really be using automated tools such as Gulp/Grunt. See more on this here.

 

4. Refactor your code
The code that you wrote a year ago might be using dated practices or you may not have known stuff that you know now. With this in mind you can look at the code and try to rewrite it using more efficient methods. For example, instead of using loops, use inbuilt functions. This will also help if your code is on GitHub, as potential employers will be impressed by the use of good techniques.

 

5. Distribute your site assets
Nowadays you can distribute your assets in different locations around the world (this is called CDN, content delivery network) This means that users will not all be making requests to your servers in London. There is a free service called https://www.cloudflare.com/ that does this for you and it also offers additional services for free.

 

6. Use CDN for libraries
If you are using other libraries such as JQuery, Angular etc they all have CDN sites which you can link to. The chances are your browser will have already requested these for other sites, reducing the load time further.

 

7. Enable compression
This is as easy as adding a few lines to your server’s conf file and restarting the server. This will reduce the file size whilst it is being sent over the internet. The most common algorithm used is called GZIP.  (https://gtmetrix.com/enable-gzip-compression.html)

 

8. Browser Caching
If you use expire headers, this will ensure that your browser retains the copy of your pages for a certain amount of time thereby reducing loading time on subsequent visits.

 

9. Upgrade your server
If all else fails you should consider moving/upgrading your hosting. If you are still using shared hosting, it’s time to go to the cloud.

Here are a list of tools that may help you test the speed of your sites and also offer some suggestions on how to improve: