Things every developer should know to improve site performance
Tags: websiteperformance, siteoptimization, webdev, backendoptimization
Published: 2019-10-04 17:54:17

---
title: Things every developer should know to improve site performance
published: true
date: 2019-10-03 12:58:26 UTC
tags: Website performance,site optimization,web development, backend optimization
canonical_url: http://blog.adnansiddiqi.me/things-every-developer-should-know-to-improve-site-performance/
---

## ![](http://blog.adnansiddiqi.me/wp-content/uploads/2019/09/speed_optim.jpg)

## Introduction

Hundreds of websites/web apps are being launched every day for different purposes. Poorly optimized websites not only leave a bad impact on visitors but also hurt businesses. While more and more people [visiting websites on their mobile devices](https://www.broadbandsearch.net/blog/mobile-desktop-internet-usage-statistics), it is very important to make them load fast. In this post, I am going to discuss a few things that every developer should know while building or updating a website to load them fast. I will categorize these issues into two sections: Frontend and Backend.

## Types of Optimization

- **Frontend:-** In which CSS, JS and at times HTML is refactored and optimized one way or other.
- **Backend:-** Databases; indices, queries etc. Middle tier components.

We must know what to fix and it is only possible how to measure. There are two tools that should give you a kickstart:

- [WebPageTest](https://www.webpagetest.org/):- This website takes an URL as an input and gives details about delays related to requests.

![](http://blog.adnansiddiqi.me/wp-content/uploads/2019/09/Screenshot-2019-09-30-at-3.01.46-PM.png)

- [Google Page Speed:-](https://developers.google.com/speed/pagespeed/insights/) A tool by Google gives suggestions as prescribed by Google for the input URL. It also provides tool to minimize files and pictures.

![](http://blog.adnansiddiqi.me/wp-content/uploads/2019/09/Screenshot-2019-09-30-at-3.02.53-PM.png)

Let’s discuss frontend optimization first.

### Frontend Optimization

We will mainly be discussing CSS and JS optimization here. When we are discussing frontend optimization it is mostly about reducing a number of requests to the server, especially for static resources (_JS, CSS, Images etc_).

#### CSS Optimization

It is mainly about merging and minification of CSS files.

1. **Merge CSS:-** Instead of loading multiple CSS files, combine all into one and then just load it. NPM tools like _concat-css_ can be used for the purpose. Tools like _Shrinker_([http://shrinker.ch](http://shrinker.ch)) could serve the purpose.
2. **Minify CSS files:-** Once files are merged, you can make them further efficient by minifying them. Minifying converts long variable and method name to a few character words thus decrease the file size. Online minify tools like [CSSMinifier](https://cssminifier.com/) can help here.

#### JS Optimization

Like CSS it is also about merging and minifying files.

- **Merge JS files:-** Like CSS, you must merge multiple files for the same purpose. The took like [_JSCompress_](http://jscompress.com) should help you here.
- **Minify CSS files:-** Once files are merged, you can make them further efficient by minifying them. They are minified for the same reason: to convert long variables/function to small one hence reducing file size. [_JavaScript_ _minifer_](https://javascript-minifier.com/) could serve the purpose.

#### Using CDN

Content Delivery Networks aka CDNs is a set of services distributed across different geographical locations thus make loading assets faster based on the requester’s location via IP Address. Static assets like images, CSS or JS are usually served via CDN. CDN services like Amazon S3 or Cloudflare could be used for the purpose.

#### Reducing WebFonts usage

Reduce Web fonts usage hence they add additional requests.

### Backend Optimization

I will be covering mostly the database because it is the main bottleneck. Caching is also used to take care of it.

- **Indexes:-** Make sure your database tables are properly indexed. As a rule of thumb index the fields which you want to retrieve by using **WHERE,**  **OrderBy**  **or**  **GroupBy** clause.
- **Avoid inserts in loop(Bulk Inserts):-** If you are inserting multiple records in a loop, instead of INSERTing in a loop, you should prepare an array kind of data structure and then make a bulk insert. MySQL provides such facility.
- **Use Where IN:-** Instead of retrieving a single record you must use whereIn(..) instead of where = \<value\> while retrieving, updating or deleting records.
- **Joins:-** Instead of running a SELECT on a table and then SELECT records in a loop from other tables, you should use JOIN where possible.
- **LIKE:-** When using LIKE with multiple columns and with OR condition, it is better to use UNION which would run much faster.  
**_select from users where_**  **_first\_name_**  **_like ‘ABC%’ union all select from students where_**  **_last\_name_**  **_like ‘ABC%’_**  **_;_**  
_is faster than_ **_:_**  
**_select \* from users where_**  **_first\_name_**  **_like ‘ABC%’ or_**  **_last\_name_**  **_like ‘ABC%’ ;_**
- **Cache:-** There are often parts of the system which are hardly updated or never updated at all. The best way to deal with such parts is to either cache it or convert static HTML of such parts. Frameworks like Laravel, Ruby, and Django provide Query and HTML cache facilities.

## Conclusion

So, as you learned that how applying these techniques can not only help to improve your sites but also help to become a better developer. Give your feedback and share your tips to make a website faster as I just can’t cover every tip right here.