Only ONE CSS file, at the very top of the page. EDIT: if it's a frequently-accessed page, include all the CSS inline. (avoid @include, too)
- Not a good name at all
Only ONE Javascript file, at the very bottom of the page (below the </html> tag if you can arrange it)
- Not a good name at all
All static content (images, CSS, JS, Flash) served with a Cache-Control: max-age= header; set the max-age to a VERY long time.
- Not a good name at all
NEVER, EVER, EVER allow <script> tags in the middle of the page or directly associated with a link (e.g., no <a href="javascript:...."> functions).
- Not a good name at all
Store your static content (images, CSS, JS) on an edge-cache — you can do this pretty cheapy via Amazon S3.
- Not a good name at all
Optimize your images and compress your CS and JS files so that consume as little space as possible.
- Not a good name at all
Was just going to say that -- and use shorthand in your CSS
- Shey
A good CMS should do all these things for you, Drupal for example includes CSS and JS aggregation, with modules for minifying.
- Mike Chelen
Turn all your frequently-used images (icons, not content images) into sprites: the result is ONE download from the server per session, instead of dozens per page view. TCP connections are the real killer.
- Not a good name at all
One of the big killers is inline Javascript: browsers will do most things in parallel; however, if it encounters a <script> tag, it must halt all ongoing parallel operations, fetch and execute the script in single-threaded mode, and then go back to reading the page in parallel.
- Not a good name at all
There. I just saved you $750.00 for your next "Web Programming for Performance" workshop.
- Not a good name at all
I'm not grokking item 1.edit. Is performance really better on a high access page to have CSS all inline instead of linking a CSS file?
- Arlan K.
It is measurably faster. The time involved in setting up, connecting, transferring, ACKing, and closing an extra TCP connection to download the stylesheet is MUCH slower than loading the CSS inline. This is less true if you have users who repeatedly visit the same page; in this case, if the CSS is cached, they won't have to reload it each time. But pages where most visitors are new, the inline CSS can really reduce the page load time.
- Not a good name at all
Some of these are at odds with best development practice, such as keeping all your modules of functionality in separate components (in this case, javascript files). But you can have a build-time script that can combine all the separate files into one for you. It would be extremely impractical to code in one giant JS file (or CSS files either, honestly).
- Lindsay
these are good rules of thumb, but i agree with Lindsay, some of these are at odds with other development practices. depends on what kind of site or page you're authoring i suppose, and imho, on how much access or control you have over your server. I like: http://www.websiteoptimization.com/service...
- .LAG liked that
Javascript can be aggregated, minified, and compressed at run time using server libraries such as JSmin or YUI. Some of the various algorithms are compared here: http://compressorrater.thruhere.net/
- Mike Chelen
We (Yahoo!) use a edge-cache tool that will concatenate all your JS or CSS files together. So you can develop independently, but serve all together. Also, we're talking performance—performance is sometimes at odds with what's good for developers :)
- Not a good name at all
I admire Steve Souders' passion in web performance. I've read his articles and books. I'm sure you've met him at Yahoo!
- AJ Batac :)
Yes. This post is pretty much a basic summary of all the YUI performance guidelines. If you look at http://news.yahoo.com and View Source…, you'll see most of these in action. The one thing we (as engineers) can't control are the ads that get placed on the page.
- Not a good name at all
Oh, I see about the CSS now. High-access but most first time visitors, makes sense. I kept thinking of high-access repeated use situations.
- Arlan K.
But, if you aggregate and minify for each individual page, based on the particular modules you're using, aren't you sacrificing the ability to cache certain elements that are used on multiple pages? I agree completely with keeping the CSS and JS calls to a minimum, but I'd be curious to see how calling two or three JS files (at least one of them, such as the jQuery library, cached from another page) compares to calling a single aggregated file that's not cached (because it differs from the file found on other pages)
- Curdy G
That said, though, these are some great tips and it's nice to see them in one place.
- Curdy G
Wordpress (namely its plugins) are horrible for this type of performance. All plugins that utilize js seem to add 2 or 3 js calls to the head, and a lot of them add that many extra css calls. :( The worst part is, they seem to add it to all pages, even when it's not necessary.
- Curdy G
from iPhone
Wordpress and Drupal are definitely the worst culprits for multiple head calls. Drupal does do decent aggregation if you structure your themes properly, but it's still not great
- Mo Kargas
How does one go about fixing it in Wordpress.... (Perhaps discuss outside this post?)
- SAM
SAM - if I get a chance, I'll try to write a blog post about it in the next few days. The first step, though, would be not to use plugins to do something you could do easily by simply editing your theme.
- Curdy G
from iPhone
Cool... I'll stay tuned for that Curtiss... Please DM me when you post it if it's no bother. :)
- SAM
Mike... that looks cool. Will backup site and give it a go tonight!
- SAM
That's awesome, mike. I'd never seen that one before. I'll have to give it a shot. SAM - I definitely will.
- Curdy G
from iPhone
FYI, I posted Glen's tips on the HTMLCenter blog, just in case FF isn't available when you go looking for them. Thanks, Glen. http://www.htmlcenter.com/blog...
- Curdy G