Yslow is a tool to help you speed up your website. It’s an add-on for Firefox—or rather, an add-on to an add-on: Yslow installs on top of the popular Firebug add-on. So first you install Firebug, then you install Yslow.
Mike Hopley provides an indepth look at how YSlow works to improve the speed of your website. Don’t settle for a failing grade. Let Mike help you get an A!
Yslow: going from F to A
An introduction to Yslow
Yslow is a tool to help you speed up your website. It’s an add-on for Firefox—or rather, an add-on to an add-on: Yslow installs on top of the popular Firebug add-on. So first you install Firebug, then you install Yslow.
When you run Yslow, it will analyse your web page according to 13 performance rules; for each rule, you receive a grade from A (best) to F (fail). You also receive an overall grade and a score (out of 100). At the time of writing, both Google.com and Yahoo.com score 96 (a high A); most websites get an F grade.
The scoring might seem harsh, and you might be tempted to dismiss these performance rules; but Yslow has been created by Yahoo’s Exceptional Performance team, and their rules deserve your respect. If you follow the rules to the best of your ability, improving your Yslow score, then you will see a significant performance improvement for your website.
If you look at the rules, you may notice a common theme: they are all concerned with components of your web page, such as javascript files, stylesheets, and images. The rules ignore the speed of your server, your databases, and other back-end issues—these only account for about 10–20% of the response time. The other 80–90% of response time is spent on the front-end; this is Yahoo’s golden rule
of performance. You may also notice that the rules say nothing about your actual HTML coding practices; again, that’s because the efficiency of your markup has little effect on the performance of your pages: (X)HTML accounts for only about 5% of front-end response time, with the other 95% chewed up by components (JS, CSS, images, Flash, and so on). Next time a markup purist declares that you should use the minimum possible HTML, because it makes your site much faster
, please point him in the direction of Yahoo’s Exceptional Performance team, who know better.
Using Yslow: from F to A
Before you start using Yslow, bear in mind that it’s a serious optimisation tool for webmasters who have already covered the basics. For example, Yslow won’t warn you when you have large images that could be compressed. If your files are just too damn large, then you should worry about that first.
When I first ran Yslow, I was surprised by my grade: an F (55). I was expecting to score well; I was expecting Yslow to pat me on the back for my good code. Not so! It turned out I had plenty of room for improvement.
Probably no-one here can afford a decent CDN (I know I can’t). In practice, this means that your maximum score is limited to 90; so in order to get an A grade, everything else must be perfect. You may also be further limited by other practical constraints—in particular, your score can be crippled by ads. With this in mind, just try to get your score as high as you reasonably can. Remember that most websites, even large corporate ones, score an F (here’s a few: ibm.com, unilever.com, goldmansachs.com, bp.com). Even a C grade is an achievement to be proud of.
Let’s go through each performance rule. Here’s the website I was working on: The Badminton Bible
1. Make fewer HTTP requests
For this rule, Yslow separately counts your javascript files, CSS files, and CSS images; it deducts points when you have too many. The following are the maximum numbers you can have without losing any points:
- 2 stylesheets
- 3 javascript files
- 6 CSS background images
It’s important to note that Yslow does not deduct points for content images (<img>). This means that you could inflate your Yslow score by using <img> for decorative images! This would be a silly thing to do: the HTTP request is still there, even though Yslow doesn’t penalise you for it. However, this helps explain why some badly-coded sites get quite good Yslow scores.
The first two items were not a problem. I have one screen stylesheet and one print stylesheet; and I had three javascript files. I had around 30 CSS images, however.
I used Smartsprites to help make CSS sprites. This utility takes most of the work out of creating and positioning your CSS sprites. Unfortunately it’s a pain to install: you need to install and configure Apache Ant first.
Creating the CSS sprites was the single most time-consuming item on my Yslow shopping list—by far. It takes a fair amount of patience. I added them only a few images at a time, and checked the results. I found that, although Smartsprites did most of the work, I still needed to edit the new CSS occasionally: Smartsprites is not clever enough to do everything automatically. I also had to edit one of the sprites, just slightly, to remove a small blemish.
I divided my images into four sprites: two non-repeating, one vertically repeating, and one horizontally repeating. For instance, here’s one of my sprites (this link is guaranteed to go stale; note the version suffix, and see rule 3!).
Overall, this rule is quite important; but the CSS images part is definitely the hardest thing to implement. If you’re in a hurry or impatient, this is not the place to start!
2. Use a CDN
You’re having a laugh.
Good for Yahoo; absurdly expensive for me. I’ll pass, thanks, and dream of the day when I have enough money to throw some at Akamai.
For the uninitiated: CDN stands for “Content Delivery Network” (the D can also stand for “Distribution”). Instead of using only one server, your website resources are served from a whole network of servers spread across the globe. As well as reducing the distance between server and client, this helps you to spread resources across multiple hostnames and thereby increase parallel downloads. Yahoo recommends a minimum of 2 and a maximum of 4 hostnames (see rule 9). Needless to say, commercial CDNs cost more money than most website owners can afford. There are some free alternatives such as CoralCDN, but these don’t seem to provide the same service (they are intended more to guard you from bandwidth spikes than to speed up your pages).
If you can’t afford a proper CDN, then tinkering with a free one is probably a waste of time; you might even slow your website down. When Yahoo say, “Use a CDN”, they are not thinking of Coral. You can’t get everything for free.





September 16th, 2008 at 12:16 pm
For the CDN thing, I think we can simply use Google Code as a workaround, just like Dean Edwards does on his personal site. Sure, it isn’t a proper CDN, but it’s hosted on Google and they had no complaints about it when asked by Dean. Don’t know if it works out for the score though.
September 17th, 2008 at 4:35 am
It’s certainly possible, but it’s clearly not going to provide the same advantages as commercial CDNs.
There’s no point using a CDN unless it actually improves the performance of your website. Bear in mind that free hosting, even from Google, may be slower than your paid-for web hosting. It’s no good distributing your files across other servers if those servers turn out to be slow.
But of course, I just don’t know. You would have to test it to find out.
If you just want to trick Yslow into giving you a higher score, then see here: http://www.anothercaffeinatedday.com/blog/default/penquin/2008/02/20/Hack-YSlow-to-ignore-CDNs-a-HOWTO-part-deux.html
September 19th, 2008 at 6:16 pm
Amazon is launching pay-as-you go CDN service. It has reasonable prices since you do not need to make a contract. Just pay as much as you use the service.
http://aws.typepad.com/aws/2008/09/were-never-cont.html
September 23rd, 2008 at 2:30 pm
The Amazon service looks interesting. I also came across simple CDN recently, which appears to have a sensible pricing model: http://www.simplecdn.com/.
Perhaps adopting a CDN is not so unreasonable after all!
I think I’ll wait and see what Amazon’s offering turns out to be like.
October 14th, 2008 at 11:54 am
I totally liked this story, I’m truly waiting to reading more of your threads!
October 25th, 2008 at 5:42 pm
Hi Mike,
Glad to hear that SmartSprites turned out useful in getting an A in YSlow! The dependency on Ant was indeed annoying, so I’ve just released another version that adds the conventional command-line interface. The new version is available as usual from http://smartsprites.osinski.name.
October 27th, 2008 at 3:58 am
Greets! Really amazing. keep working! Tnx! Saw!
October 27th, 2008 at 9:01 am
Stanislaw,
Great to see those new developments in SmartSprites. It’s an excellent tool, without which CSS spriting would have been abjectly miserable.
November 3rd, 2008 at 1:49 am
According to Google their AJAX Libraries API project hosts the JS (jQuery, MooTools, etc) on their infrastructure and is a true CDN. I would trust their systems more than any other CDN, including Akamai.
In my testing, I can download jQuery in about 100ms (on average) from Google’s server.
November 3rd, 2008 at 8:40 am
Interesting idea, Dan.
Advantages: a free and fast CDN for one component, and the browser may already have cached Google’s copy of jquery.js from visiting other websites.
Disadvantage: adds an extra HTTP request, because you’ll now need two javascript files (Google’s jQuery copy, plus your own JS). Because JS blocks parellel downloads, the browser must wait for the DNS lookup and the download from Google before it does anything else.
Having said that, the blocking of parallel downloads isn’t an issue when your javascript is at the bottom of the page anyway. So the only real disadvantage is the added HTTP request.
November 14th, 2008 at 7:38 am
I’ve just realised that you can combine ALL your stylesheets into one file — even if they are for different media.
For example, I have screen and print stylesheets. Instead of using two [link] elements, I can use one [link media="screen, print"]. Inside the stylesheet, I can specify which CSS applies to which media, by using the @media rule:
@media screen {
body { font-family: Verdana, Geneva, Arial, sans-serif; }
/* Rest of the screen stylesheet goes here */
}
@media print {
body { font-family: Georgia, “Times New Roman”, serif; }
/* Rest of the print stylesheet goes here */
}
This saves me one HTTP request (browsers will download print stylesheets). You might want to be careful if using this with handheld styles: that would force handheld devices to download the screen styles, which they might otherwise skip entirely.
W3C on media types: http://www.w3.org/TR/CSS2/media.html
December 12th, 2008 at 9:38 am
Amazon have released their CDN, called Cloudfront, which should be affordable for any website owner; you only pay for what you use.
http://aws.amazon.com/cloudfront/
I will definitely be trying it out, when I eventually get time to spend on optimisation.
I believe they do not (yet) offer Gzipping, so it might be best to keep your javascript and CSS on your own server for now.