Are you challenged by slow page load times? You can shorten the time it takes to load your page and possibly improve your Google search ranking by altering your .htaccess file.
What is an .htaccess file?
An .htaccess file is a file used on Apache webservers to configure the server software. This is done so that the server software behaves in particular ways to either enable or disable certain functions that server features. There are many uses for this file, such as redirecting URLs, rewriting URLs, protecting sensitive parts of a website or even blocking specific IP addresses.
Always take care when updating these files as even the smallest typing error could result in problems for the website. Errors could cause pages and functions on a website to become unavailable, or even make the entire website itself unreachable. Always backup the file and test the changes made to militate against any potential issues you may have unwittingly caused.
There are other server types out there so such as Nginx, Microsoft’s IIS and Google’s GWS. However, Apache has a larger share of sites using it currently, which is why I’ve decided to cover it in this post.
Why should you try and speed up your site’s page load times?
There are two very good reasons why you should try to improve your site’s page load times: user experience and improved search ranking.
User Experience Generally speaking, most users are not happy waiting excessively long for a page to load, especially if they are browsing multiple pages on the same site with the same wait times. It stands to reason that the faster a user’s browser can load a page, the better experience that user will have.
This can have an impact on your site’s sales, signups and repeat visits. Now more than ever, with users’ Internet speeds increasing, your page load speed will be more noticeable if it’s slow, and this could affect engagement and your bottom line.
Search Rankings There are a few reasons that a faster page speed can improve your site’s rankings both directly and indirectly:
- Faster Crawling Speed If a search engine robot can crawl your site faster, it is more likely to crawl all of your pages and content without timing out. A slower crawl may mean vital pages or relevant content is missed, and thus the opportunity to rank higher is lost.
- Google Loves It Google uses site speed in its ranking algorithm (and has since 2010), and this is one of the direct ways that a fast or slow load time can have an effect on your search engine rankings. Google are obsessed with speed, and this is reflected in them publicly stating that they are using it in their algorithm. This is even more important now with the increased number of mobile users over cellular networks.
- Reduced Bounce Rates More of an indirect factor here, but if your site has a slow page load time you are more likely to have a higher bounce rate. Users go back to the search results in search of a faster site to get what they were after would count as a bounce, and this could hurt your search rankings.
How can you speed up a page load by using your .htaccess?
Below are a few quick ways that you can improve your load times with your .htaccess file. I definitely recommend backing up the original file and testing your site after each change before finalizing any update.
This will prevent any unintended issues that may come up on the site through errors or typos in the file edits.
GZIP Compression Simply put, compressing your files makes them smaller and quicker for them to be transferred and loaded. Directing your webserver to enable GZIP compression can be a great quick win when speeding up load times. To do this you need to add the following to your .htaccess file:
Once you’ve updated the file, you can test to see if it is working. This tool also shows by how much the files are being compressed. Enable Browser Caching When a browser reaches a page, it has to load several things that very rarely change, like certain style sheets and logos for example. By setting expiry headers for files on your site, you are effectively telling the browser to save them locally on the user’s computer. This means that the next time the user visits the site, less data needs to be downloaded.
Adding the code below to the top of your .htaccess file will tell browsers to save files for return visits:
If your files change more regularly, you can update the code above to ‘1 week’ or remove a file type if you do not want it cached at all. Remember though that if you make changes to the pages in between a user visiting and the time you’ve set the cache to expire, they may not see the new version right away.
Enabling Keep Alive Enabling Keep Alive is basically a way for the webserver to tell the browser that it doesn’t need to make a separate request for each file it retrieves on a site. This cuts down the brief latency following a request for a resource and downloading it on the browser. Check here before adding the code below, as in many instances this could have been added by default on the webserver.
Deny Spam Bots Access Sometimes a page load speed can be reduced by the bandwidth you have available on your hosting plan. This can be even further reduced if your site is sharing a server with others. The last thing you need then is for spam bots to take even more of your bandwidth away as they crawl your site for whatever reason they were created for (usually to mess up your analytics data)! There are two ways to do this; one is to block them and the other is to redirect them away, although this in itself could slow the site loading down.
There are a few other ways to improve a page load time that don’t need any changes to your webservers config files. A few of them are below:
- Go for dedicated server web hosting
- Pick a server in or as close to your target audience (not in Germany when you target the US for example)
- Use a Content Delivery Network (CDN) to cache and serve resources faster
- Minimise the amount of redirects on a page
- Remove (where possible) query strings from static files/links
- Compress images and where appropriate use CSS image sprites
- Combine Java Script and CSS files where possible
- Avoid unnecessary repetition of CSS
If you want to benchmark your site load times to see how much each of these .htaccess updates can speed things up you can try using tools.pingdom or gtmetrix for free.
Are there any other areas you can think of to improve page load times? Share them in the comments and help to improve the speed of the web!