Speed Up Your Website: Part Deuce
Last week I wrote a post about what I was doing to speed up my website. While that post is an informative, well-written piece of literary genius, it didn’t go into a whole lot of detail. That detail is in this post, because two posts are better than one. I’ve tweaked, found problems, fixed a few problems, and learned a thing or two. I also learned there is a lot to learn.
I’ll mostly talk about wordpress in this post, but many of these tools and resources are not wordpress specific.
Taming HTTP Requests
Also consider using CSS sprites rather than loading a lot of images.
The point is, look around for a way to limit the HTTP requests, if something is loading that shouldn’t be get rid of it. This is one of the easiest ways to speed up your website, so limit your requests.
As someone who designs themes for public use, I usually don’t hard code links, titles, and whatnot even on my personal sites. This creates excess SQL queries, which take time, and time, keeps on ticking. Don’t use a wordpress tag or database query when simple beautiful fast HTML will do.
This goes for any CMS, and while this may be more relevant for large sites it can’t hurt to think big when your a little guy.
WP Super Cache
This one is wordpress specific, but there are lots of ways to cache your website. WP Super Cache converts your page into a static, pure HTML file for users that have not logged in or left a comment. There are two big advantages to this:
1. You don’t make any unnecessary database queries(see above point). This keeps your database server from crashing.
2. Most of your visitors will get a compressed static HTML file. This is the fastest way to get the page loaded and up on the screen. Once the user leaves a comment or logs in, they see a wp-cache page which is more dynamic, yet still fast.
If you plan on receiving a lot of traffic, WP Super Cache is a must, and at the very least you should use WP-Cache. I use wp super cache on and love it, it has not failed me yet.
use used phpSpeedy to take care of compression. Getting this to work can be tricky depending on your website, but it is generally easy to set up. The author of phpspeedy is very supportive so I suggest at least trying this out. It is still very new but the speed at which it has been developed has made me a believer.
There are two versions of this script, a wordpress plugin and a php script to be used however you want. I don’t use phpSpeedy anymore as I do all the things it does via the server now, in my case I found this simpler.
An expires header essentially tells the browser to cache things and for how long. At first this may be confusing as there is some Apache mumbo jumbo talk to get around, but it is really easy. If you are at all familiar with .htacces files you will have no problem setting far futures expires headers.
Here is an example of the code you would add to your .htaccess. This bit of code is going to add a expires header to your media files.
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT" </FilesMatch>
NOTE: Far future expire headers are going to be for files that do not change regularly. The browser is going to cache the file and not look back until the year 2010! The name of the file must be changed if you change the file(using version numbers is a good way to do this, which can also be automated).
That being said, you can set the files to expire in any amount of time you want, I currently have most images set to expire after a few weeks. Like so:
ExpiresActive On ExpiresDefault A0 <FilesMatch "\.(gif|jpg|jpeg|png|swf)$"> ExpiresDefault A3600 Header append Cache-Control "public" </FilesMatch>
If you have files that need compressed and wordpress, your CMS, or some other software isn’t already compressing them, you can do it all via the server(which is also faster). Askapache.com has a tutorial on adding compression. Even the smallest files can be reduced and this can have a major impact on loading times.
Just the Beginning
There are plenty of reasons why a website can be slow, and a way to fix each and every one of them. I have only gone into what I believe are the easiest and best ways to speed up a website. If you want more, tell me, or check out the sites below.
- Yahoo – An exhausting read with a ton of information you need to know.
- Roscript – The somewhat shorter version of yahoo’s list.
- Die.net – Are you a geek? Do you like charts? If so, then you should read this, some awesome information, benchmarking and testing in this article
- Apache .htaccess tutorial – A tutorial from the source, if you want to know the power of .htaccess you should read this.
- Ask Apache – more .htaccess tutorials.