Add an Expires or Cache Control Header
This is perhaps one of the single most important optimizations you can make that will both assist your server by reducing load as well as making your visitors experience while on your site more enjoyable, faster and in turn make them more likely to stay longer, visit more often and view more pages. I will start out with a brief explanation of the concept behind this and provide the solution that you can easily use for your own site, provided your server supports the methods I will outline here.
When a visitor comes to your site for the first time their browser will request every piece of content that your site uses to make up whatever page they end up on, this can amount to a few Kilobytes or a possibly even a few Megabytes (or more if you get out of control) or content that your server has to send down the pipe to your visitors computer in order to display the page they are viewing. I’ll use an analogy here and hopefully it will make sense, if you are having a party and at this party you have a keg of beer and only 5 people show up because you are playing nothing but the Bee Gees and you smell funny it’s not a big deal if they grab a new glass when they come back to the keg for a refill, but what if you have 2500 people at your party and they all take a new glass every time they top off, wouldn’t it make a lot more sense for them to just keep the glass they have and use it again? After all they already have it and it is identical to all the other glasses sitting there. The same concept applies to your site, send them the content once, give their browser the information it needs to cache it so the next time they view your site, or another page on your site they don’t have to download the items they already have all over again, it really is just common sense were talking about here.
Setting up expire headers is very easy, if you have access to your httpd.conf file you should use that, otherwise you can add the required information to the .htaccess file that is located in your sites root folder. I won’t blab too much as this will be pretty self explanatory, any extension you see listed here will be cached for the length of time specified. This is the code I am using on this site and it should work well for you as long as you remember that what I just said about the dangers of caching certain content for long periods of time.
ExpiresDefault "access plus 1 year"
That’s all there is to it, add that and your content will be held in cache by browsers that support it (read all good ones) for the period specified unless you rename the file. Now, moving on to the next step.
Compress Components with GZIP
A good analogy for this would be the exchanging of money, if you go into a store and spend $50.00 on something it makes sense to pay for that purchase with the smallest number of bills possible right? So it would be nice if you hand the cashier a single $50.00 bill and call it a day but if you aren’t able to pay with one bill, or generally like to be a jerk you can pay with with other methods, even with pennies and they have to accept it. The end result is the same, it just takes a lot longer to get to the end result and that cashier is likely going to want to beat you before you leave.
Using compression on your site is very similar, it will allow you to compress your content and send the least amount of data to your visitors computer as possible, when combined with proper caching this can lead to HUGE improvements in your websites performance with just a little added server load when you send the content to them the first time. Enabling compression is again a very easy task, as long as you are able to configure your server to do it or you are on a host that will allow you to do it. For GZIP compression to work it has to be enabled on your server, in Apache you will need mod_deflate and then you need to tell the server to compress your content, again this snippet should be added to your httpd.conf file if you can, or you can add it to your .htaccess file in your sites root folder. This is what I use on this site, your mileage may vary :-)
As you can see, I am pretty much compressing everything possible except images which are already compressed anyhow so that would be a waste. that’s it for this tidbit, add the code and save file, restart Apache if you added it to your httpd.conf file and you are good to go.