How to Make Fewer HTTP Requests for Faster Website

Reducing the number of HTTP requests is one of the keys to faster website. So, how do you make fewer HTTP requests? The answer is simple – by reducing the number of files. Let’s see how to make fewer HTTP requests.

How to reduce the number of CSS and JavaScript files

Every external CSS and JavaScript files need a new HTTP request. The idea is simple. By combining all CSS files into a single file, and by combining all JavaScript files into another file, the number of files to download is reduced and so are the requests.

CSS files should always be placed in the head section. It’s because they block page rendering. JavaScript files, on the other hand, block all rendering and parallel downloads for whatever that follows. Try and place as much JavaScript as possible it not all at the end of the document, preferably, just before the closing body tag.

How to reduce the number of Images

There are quite a few techniques to reduce the number of images. The first thing you should do is to decide whether the image is actually needed or not?

With web fonts, you can create beautiful typography that looks sharp on all resolutions and all zoom levels. CSS3 features combined with popular font libraries like Font Awesome will let you create social buttons and much more using just a few bytes and will be resolution independent.

If your site is using a lot of small background images, then consider using image sprites. An image sprite is a single image that contains multiple images. The required portion of the image sprite is shown using CSS background property.

Another great technique is to use lazy load for all images that are not visible when the page loads for the first time. There are many great jQuery plugins which do this automatically.

Yet another way to reduce the number of images is to encode small images as base 64 and embed them directly in the document using data URI.

Final Thoughts on Fewer HTTP Requests

As HTTP/2 gains popularity, you won’t need to make fewer HTTP requests anymore. HTTP/2 makes all the above techniques obsolete with single multiplexed connection. But, for now, the techniques explained above will help you make fewer HTTP requests and will certainly help make your website faster.