Improving Website Performance By Optimizing Your HTAccess File
One of the lesser known optimization methods for improving website loading speed is to work on a file that lives on your server. This special file is called the .htaccess file. This is usually a hidden file (hence the "." before the name of the file. Placing a dot before the file name will hide the file from regular viewing, so you will need to make sure your host or your FTP software can see hidden files like this. This file is hidden for good reason. It can break your website in an instant if used improperly.
What can the .HTAccess file do?
This file is very flexible as it can be used to redirect people from your "www" version of your website to your non www or vice versa. It can also be used to block specific URLs from being shown as well as stopping traffic from specific referral sources from trying to use up your bandwidth. This file can also be used for optimization of your website too. Specifically with the expires settings.
Optimizing the HTAccess File.
A website is made up of many different parts, however, many of them do not change over time. For example, the favicon that is used on the website will most likely not change day over day, week over week, or even month over month. So, if you can communicate this to the web browser so it can cache it, you can save valuable time on the next viewing of a page within your website. Let's say for example, your logo is on every page. This logo is an image file. So on the first request of this file, you have the browser download this to the user's cache. On the next page they visit on your website, the browser recognizes that this file has already been downloaded so it should just pull from the cache instead of having to redownload. That special recognition is from expires headers.
Expires headers can be applied to file types. For example, the favicon, CSS, JavaScript, and image files. The expires duration can depend on the file type and how often it would change on your website. You may have a file (like your logo) that will not change very often - so you can set the expires header to a full year for that file. But let's say you have been changing your favicon around, you may wish to set your expires to 1 week instead of a long time. By setting expires headers, you allow people to have a better experience on your website by making it faster once they visit for the first time.
There are other ways to improve your website loading speed!
Check out our article on the other methods to improve the speed of your website.