Tuesday, December 22, 2009

Speed up your page with htaccess file

I mentioned the other week that Google may be beginning to put more importance on page loading times and speeds. There are some handy tools out there to suggest some of the ways you can improve page load times, and therefore the overall speed. I will try and tackle some of these issues, but in a few seperate posts. The reason for this is that personally, I'm not a designer or a programmer, so many of the suggestions I have come across for my own sites and sites that I manage have left me a little stumped, and I have had to research a little. For those of you already competent in HTML, CSS, and other programming elements of websites, this may be all too easy for you!

Page Speeed with htaccess - Barcelona SEO blog

So, first one is your .htaccess file. This is a file stored on your server, and is very often empty. It is a simple text file, so if you need to open the file, you always need to do so in a simple program such as notepad, or something similar - never dreamweaver or Microsoft Word - those programmes have unseen code which can interfere with the file. Some sites I've found talking about the htaccess file mention that if you don't find it on your server, you should ask your hosting company if they will accept such a file. I have to say that I haven't found this to be a problem so far. BUT it's probably better to ask, as it can affect download times for servers, and can therefore affect other sites if you're on a shared server, for example.

So, what's the big deal with the .htaccess file?! Well, before we start, it's always wise (as with anything on your website) to make a back up of anything on your server before you start to modify it. The htaccess file is a file which can isntruct the bots on the search engines with regards 301 redirects, custom error pages, etc. and other such operations as cache of elements, images, etc. This is a big deal for page speed.

So if you have no experience with adding instructions to a htaccess file, then it's fairly simple. Each command needs to be on one line only (so potentially the file can be as long as you need it to be). And like html, each command needs to have a start and end. So, say you want to cache all of your image files, as reccommended by pagespeed on Firefox, which I mentioned in the last post. You need to add this to the htaccess file:

< Files img >
Header set Cache-Control "max-age=29030400, public"
< / Files >

To break it down. The tag of < files > can be followed by a space and then any file extension you have and want to cache.

The following line needs to copied exactly, and basically tells the bot how long to chache the files for. The numbers are in seconds, and those figures represent a year.

If you prefer to cache individual images, then this can also be done, if you need to chage images on your site on a regular basis. Say, for example, your logo never changes (likely), then you can add a line just for the location of your logo.

Obviously don't forget to end the command with < / Files > to close the tag, and remember that each command needs a new line.

If you have any queries, please leave them in the comments. I'll be returning to htaccess again shortly, so come back for more spage speed tips.

Not satisfied with your website? Contact me at Barcelona SEO for a chat about the things we can do. I specialise in Website Optimisation in Barcelona, but can be contacted for any particular site - regardless of the location.

*Please note, due to the built-in html editor in blogger, I have used extra spacing in the tags for clarity.

No comments: