Tips to make your website faster
Did you know that Google takes into account the speed of your website in order to know where to position it in the search results? Yes, and Google is not the only reason why your website should be quick. To avoid forcing your users to leave your website and/or your server to run out of resources, you need to ensure things run quickly.
From a mobile perspective, you have to be aware of the limits of all the devices. You can compare them for performance to computers and internet connections of five years ago: the hardware is poor and the bandwidth is generally limited compared to today's computers. We all know that mobile devices are becoming ever more popular so it's extremely important to make sure that your website is quick on these devices as well.
Speeding up your website is based on two simple things: reducing the number of requests the users make and reducing the size of the response your server sends back. Here are some useful tips:
Reduce the number of requests
Every static resource included in the HTML of your website is a request the end user will make to the website—every single image, style sheet and JavaScript. Modern browsers usually only process four static resources at a time, meaning that the more you have, the more the end user will have to wait. But how do you reduce the number of requested static resources?- Combine static images into CSS sprites: instead of having fifty different icons, create an image containing all of them and use the CSS attribute background-position to extract them. You probably already saved most of the requests sent by the user—CSS sprites are very powerful
- Combine style sheets: if you have more than one style sheet, combine them together
- Combine JavaScripts: the same as for the style sheets, merge multiple JavaScripts into a single file
- The browser cache is your friend: to avoid having the user ask the server the same resources over and over (e.g. the logo), configure your server to send back the required headers in order to have the browser cache them
Reduce the size of the response
Reducing the size of the response your server sends back drastically decreases the time the user has to wait for the page to be loaded. It’s pretty straight forward—the fewer bytes the end user has to download; the less time he will have to wait. But how…?- Compress text resources: you can easily configure your website to compress all your HTML files, style sheets and JavaScripts with the GZIP algorithm. The idea is pretty simple, the resource is compressed by the server before being sent to the end user, and decompressed by the end user’s browser as soon as it receives it. You can save between 40% and 90% of the original file size. Quite a lot, huh?
- “Minify” text resources: in English—remove all the useless characters from your HTML files, style sheets and JavaScripts. Remove all the comments, the tabulations and line-break characters from your text resources—they are useless. You can save up to 20% of the original size
- Optimise images: make sure you save the images in the correct format. Priority always goes to PNG and GIF formats; they are both very lightweight when the image has a low spectrum of colours. Use JPEG only when it’s a photographic-style image (a JPEG quality of 75% is usually enough)