In January, I interviewed Kyle Simpson on Episode 4 the ATX Web Show. We discussed Web Performance and Google’s plan to “Make the Web Faster”. Since then, Google has announced they will start rewarding your site’s page speed. And in their Webmaster Tools they hint that the bar is set at ~1.4 seconds.
80% of the time users wait for a web page is because of the frontend.
I was sort of thunderstruck with fear. Although we always strive for better, I typically found a 3-5 second page load great and up to 7 seconds acceptable. After recording the show, I stayed up a few hours that night fiddling with The ATX Web Show and increased site performance by ~500%1.
Since seeing those results, I only think about Web Optimization. I see the web in milliseconds now. If you’re like me and never considered optimization a necessity maybe now is the time to re-evaluate that. And don’t act like this isn’t your problem because 80% of the time users wait for a webpage is because of the frontend2. The goal isn’t to fit under some imaginary kilobyte threshold, the goal is to make sure that everything is as small as possible. Reduce Filesizes, Reduce Requests, and Enable Caching.
5 Steps to a Faster Website
I documented the steps I took to increase my YSlow and Page Speed grades without getting into costly CDNs and such. A lot of sites will tell you to just install a cache plugin. And while you should do that (see Step 5), it’s important to do that after you’ve optimized or else you’re just polishing a turd, curing a symptom not the disease, putting lipstick on a pig or whatever analogy you want to use. Very little of this is WordPress specific so even you dweebs on Expression Engine can optimize your sites.
Step 0: Install the Right Tools.
- Webkit Web Inspector
You’ll need to download Chrome or Safari and then enable Web Inspector. The Web Inspector’s Resources Panel has beautiful visualizations of your site’s page load waterfall and is enjoyable for benchmarking your progress after each step. - Firefox
If you don’t have this, you might be on the wrong website. You need this to install Firebug. - Firebug
You should have this already, but you need this to install YSlow and Page Speed. - YSlow
A Firebug plugin from Yahoo. It ranks your page speed and gives you a grade on various critera. - Page Speed
A Firebug plugin from Google. Page Speed is very similar to YSlow and will grade your site on various criteria and explain to you how you should improve. It’s my favorite of the two. - Webmaster Tools
If you have access, register your site with Webmaster Tools. In the Labs > Site Performance section, it will give a graph of your page load speeds recorded by Google over time.
Step 1: Minify & Optimize Your CSS
This is just a 3 step process and it’s here that I saw the majority of the site’s weight drop off. There’s about a 10% chance you’ll break something here. If you’re uncomfortable take it slow, line by line, and refresh a lot.
Minify CSS
Open up Page Speed and click “Analyze Performance”. Find the section titled “Minify CSS”. You will see download links for optimized versions of every CSS file your page calls. Replace your bloated CSS with this.
For WordPress, you’ll have to keep the theme declaration block at the top.
Unfortunately in the case of WordPress, most blogs rely on plugins which load their own assets that are rarely optimized. You may have to overwrite the CSS in some plugins. In a perfect world, WordPress plugins would come with pre-optimized assets.
This is maybe not advisable, but I hack into plugins and comment out the CSS and Javascripts they load. I’d rather write my own CSS. Be prepared to do this after every plugin update.
Learning Point: Don’t Over Qualify. Use Efficient CSS Selectors.
I always assumed it was best practice to be explicit when writing CSS, but I was wrong. It’s called “Over Qualifying” and it’s more work for your browser to sort out. Unique classes and unique elements will win in the speed game.
#header nav ul li a { ... }
/* bad. 5 selectors is way too many. */
ul.commentlist { ... }
/* bad. too conjoined. */
#header a { ... }
/* better. more direct. really nice. */
.commentlist { ... }
/* better. just the class selector should be specific enough. more agile too.*/
I covered this briefly, but Chris Coyier of CSS-Tricks has a great write up on Efficiently Rendering CSS.
Post-Minify CSS Results
I thought I was doing myself a favor making my CSS human readable, but it was adding an extra 180KB. You can take it a step further and strip out unused classes, but I personally prefer having some generic classes in my stack (like tables).
| Total Size | Load Time | |
|---|---|---|
| Pre-Minify | 248.96KB | 2.57s |
| Post-Minify | 70.82KB | 2.07s |
Step 2: Smush & Optimize Images
Your images are too fat. Photoshop’s “Save for Web” is actually pretty good at optimizing, but there’s room for more. Your images have huge amounts of useless metadata that can be stripped out. This couldn’t be easier to fix. Here are some tools to smush your images.
- Page Speed gives you a lossless smushed version of each image that can be optimized! Save As… and upload.
- YSlow > Tools > All Smush.it – this will batch shrink the images on the page and maintain folder structure. It’s unbelievably convenient.
- ImageOptim is a great offline tool (for Mac) that you can batch run whole directories with. Any image you upload to the internet should go through this before you upload from now on.
Sometimes you’ll see that you’re only saving 400B and you may think “What’s the point?” Pay attention to percentages. If an image can be 9% smaller, that means your users will get that image ~9% faster! Math.
Be sure you make backups before you replace images or smush whole directories, just in case.
If you use Adobe RGB color profiles for your images, some optimizers strip out the profile leaving you with a desaturated image. The Adobe RGB profile adds ~50KB+ and is intended for print. Use sRGB instead.
Serve Properly Scaled Images
This is pretty elementary. Where you can, serve a 200x200px wide image instead of scaling down a 400x400px wide image to 200x200px. Larger images take longer to download and resizing takes longer to render in browser.
Specify Image Dimensions
I had grown accustom being non-committal about image dimensions, but Page Speed recommends that you specify image height and width because it’s less for the browser to sort out. It gives you the rendered dimensions and you add that to your <img> tags. Total time spent completing task: 2 minutes.
SpriteMe
Use sprites. Spend some time and figure it out. It can reduce tons on HTTP Requests and make your site even faster. Google performance guru, Steve Souders, created a tool called SpriteMe that does this for you. Install the bookmarklet, and click it on your homepage, then it’ll do the rest of the work. It will pack up your sprited images, and give you some CSS to replace in your stylesheet. Skills Required: Math.
Post-Smush Image Results
Most of my savings here were due to smushing my images. You’ll see a direct correlation. 17% less kilobytes resulted in a 23% speed increase.
| Total Size | Load Time | |
|---|---|---|
| Pre-Optimize | 70.82KB | 2.07s |
| Post-Optimize | 54.66KB | 1.60s |
Step 3: Minify & Optimize JS
Just like CSS, Page Speed gives download links for minified versions of your javascript right there in the window. Grab the minified versions and drop them in your site. There’s, again, a 10% chance you’ll break something, but just take it slow and refresh often. And again, you might have break into plugins and comment out their swill.
One JS Library to Rule Them All.
If you’re loading in jQuery, Mootools, and Prototype, you’re doing something wrong. These libraries have a lot of functional overlap so you’re basically repeating yourself over and over and wasting tons of bandwidth. Have a good hard look at your plugin stack. Find out which plugins are loading what library (use paper if you have to) and try to target a single library (*ahem* jQuery *ahem*). Search for alternative plugins that use the your library of choice.
Post-Minify JS Results
Your results will vary. If you eliminated multiple JS libraries, you may see savings in the hundreds of KBs.
| Total Size | Load Time | |
|---|---|---|
| Pre-Minify | 54.66KB | 1.60s |
| Post-Minify | 39.28KB | 1.53s |
39KB is what I used to call a small image… but now, it’s a full website.
Step 4: Enable Browser Cache & GZIP in Apache with .htaccess
This took me a long time to master. I was ignorant to its proper implementation, I googled around and found a few good resources.3 If you’re on Apache (you probably are), add the following to your .htaccess file after your WordPress rules. If it’s all gibberish to you, that’s fine. Basically it does the following:
- Detects mod_deflate and GZIPs various mime types.
- Detects mod_expires and sets an expiration date for each type of asset.
- Detects mod_headers and sets Browser Cache age limits for your assets.
I’ve used this on about a dozen sites on a handful of hosts and had no problem. It will simply ignore what it can’t support. If you see improvements, please comment over at GitHub.
Post-GZIP & Browser Cache Results
The browser is now taking the brunt of the load and storage and you’ll start feeling the snappiness. The browser isn’t re-downloading images on subsequent pages, like background images, since they already exist in its cache. You’ll notice in your Inspector that you’re page loads have less long lines and more short 0 byte blips because the file is being pulled from your browser cache.
I did run into problems where GZIP showed true on GIDZipTest & HTTP Compression Test but false on Page Speed. Page Speed eventually caught up, but I was unable to get a good metric.
Step 5: WordPress Plugins for Performance
Here are some plugins to install on our final step on the way to Web Performant WordPress. Like I said at the top of the article, don’t rely on plugins to fix your sloppy code and your poor craftsmanship. Your site needs good bones. And your client deserves at least that.
WP Minify
WP Minify is a great plugin that will combine and minify all your javascript files or all your CSS files. Basically, everything I told you to do in Steps 1 and 3. If you’re lazy and skipped that section and just came here, I’m sad for your clients.
I’ve found this great for serving minified CSS that I had to keep human readable in the theme. As far as Javascript goes, it could be my problem but, I’ve never had a plugin successfully combine scripts and have them all still working in the end. Try it! If you’re able to squeeze all your javascript into one file successfully, I applaud you.
WP Super Cache
Now that your site is optimized, you’ll notice on your page load waterfall one of the longest part of your load is probably the first blue line, your HTML. This is because your site is taking a huge roundtrip:
Client Request → WordPress Server → Database → WordPress Server → Client
Turning on caching will take out that trip to the database.
Client Request → WordPress Server → Client
FASTER! It actually does quite a bit more but this is the simplified explanation.
I’ve found WP Super Cache to be wonderful for this and I highly recommend it. It’s a bit of a pain to install as you have to grant temporary permission to some directories to write, add a line to your wp-config.php, and then add some more to your .htaccess. There’s a 30% chance you’ll whitescreen your WordPress install, but just follow the directions and the end result is once you turn it on your visitors will be served HTML in milliseconds.
Final Results
Your results may vary, but I promise you’ll be on your way to a better web experience for all your users. It’s like The Biggest Loser for websites. What took me 4 hours of googling, writing blog notes and roadblocks, could probably only take you under 1 hour.
| Total Size | Load Time | |
|---|---|---|
| BEFORE | 248.96KB | 2.57s |
| AFTER | ~36KB | 796ms |
You are now one hour away from a better website. There’s no excuse to not be doing this.
Great article!
Take a look at the concept I implemented on a WordPress Plugin I developed as well.
It’s called Parallel Loading System and it will parallelize connections and optimize images on your blog.
http://bit.ly/wp-pls
Best regards!
Awesome José! I’ll it a whirl. I have just the site that could use it.
Plan on digging into this while I work on a new WP theme and setup. Thanks!
That’s great! Page Speed will guide you to glory. Just try to check of as many boxes as possible.
Excellent post, and bookmarked for future reference! :)
Nice post Dave. I haven’t seen anything about browser cache & GZIP in Apache- I’ll definitely check that out more.
One of the biggest issues I’ve seen with WordPress sites is the amount of scripts and css loaded on every page and post that aren’t necessarily needed everywhere.
Many plugins just add the contact form script, the pagenavi css, or even the dribble inline css – even when it’s not being used on that post.
That’s one of the first places I look to shed page weight and speed up a site:
http://wptheming.com/2009/12/optimize-plug-in-script-wordpress/
Thanks, Devin! I was actually going to mention this in a subsequent post but now I might just link to your article :)
Impressive, thorough post.
W3 Total Cache will do the minification and concatenation of your CSS and JS files for you, as well as all of the caching. It will also help you get set up automatically on a CDN.
Highly recommended!
I’ll look into it, thanks! I’d definitely be into trying it based on your recommendation. I might even fiddle around with this post: http://www.tutorial9.net/web-tutorials/wordpress-caching-whats-the-best-caching-plugin/ and see what i like. but so far i’ve enjoyed WP Super Cache.
I found W3 suited me the best out of the ‘major’ caching plugins. The minification section is robust (gotta love marketing terms), allowing you to include selections of scripts in one of 3 areas, and as either blocking or nonblocking (choose nonblocking unless somehow this breaks your site’s functionality).
Outputting debug as comments was also an easy way to get right at the info “is this working?”.
Don’t mean to be an ad for that plugin, but it really helped me in addition to the hand-crafted optimizations that we should all be doing.
thanks greg. don’t hesitate to comment! i’m actually using W3 on my site now. I have a few mixed feelings about it, but it’s alright.
i may update my post or even write a separate one on using W3 Total Cache.
Dave,
I wish you wrote 10 articles a day. I enjoy reading your blog more then any other website on the web.
Thanks for the great read.
@TwoGiraffes thanks for the compliment! I’ll try and write more! Got a couple things in the hopper.
Great article. I understand that your goal was to show how to speed up a site “without getting into costly CDNs.” however not all CDNs are costly. Combined with tips like yours, a CDN can help make a site very fast.
Mark Bailey
WPCDN
Very awesome article, José.
I think it’s important to note mod_deflate is Apache 2.0.x specific, while mod_gzip is for Apache 1.3.x (though I have seen some mentions of getting mod_deflate to work with Apache 2.0.x)
I came across this very issue when tediously trying to achieve an A score in YSlow. I’m sure many of us have pulled entire fist-fulls of hair out of our head while embarking on this journey. lol
I’ve been with Media Temple for a few years, using their DV server, and mod_deflate is something that needs to be enabled manually. So, if anyone else here has come across this issue and scratched their head (or pulled yet another fist-full of hair out), here’s the answer.
whoops. Awesome article, DAVE! sorry about that. ;)
Nice insight on Apache 1.3, Lee.
I totally agree with you on the hair-pulling experience. It’s so poorly documented on the web, that’s why I wrote it all down.
And thanks for the mod_deflate on MT tip. We use MT at Paravel as well but maybe it’s enabled in later DVs? Will have to investigate.
Phenomenal article, great writing, great content, great balance of practical and theoretical.
Sad I missed this when it was first published!
I really wanted to have a concrete example of enabling GZIP in Apache with .htaccess. Now I’ve got it. Thanks for that :)
This article is one of the best I ever read on the optimisation subject… Fantastic job (as usual of course:) )
sigh. WPCache is what I have installed on my personal blog and while that works just fine for output caching, it doesn’t take into account what would happen for much larger interactive sites.
#fail
Wow. Thanks man! I’m a photog myself and pageloads are really hurting the industry. I plan on using some of these tricks to (at least) make the frontend lighter and faster so people can spend that time on content.
Good. Rock. Later.
Yah. Photog sites are hard. They depend so much on preloading large images. It’s best to make sure the rest of the site is super fast so those large images seem to take less time. Let me know how it works out!
Great post Dave, I could definitely spend some time streamlining a few of the sites (WP and otherwise) I’ve built. Thanks for the starter kit!
Minify my code, i found to be the most useful for a couple of my projects.
@David: I’m totally thinking I should go ahead and Minify HTML. it’s gotta be faster right?
Awesome post!
Actually I have this same post in my drafts for the last year and a half since I became obsessed about page speed.
However your article is a classier piece of writing that I could hope to do.
Aw, shucks. But seriously, this took me 6 months to finally pull the trigger. So I know what you mean. You gotta put it through the paces. Let me know if you have any input. Faster Faster Faster!
Awesome article, but I have three words and the best caching plugin for you: W3 Total Cache…
It’s better (=faster) page cache than the Super Cache, plus automatic minification and combining of JS- and CSS-files, in addition to Database Caching with Opcode/Memcached and automatically managing Content Delivery Network for those who have access to such luxuries.
With W3 Total Cache, all that is left is optimizing images (WP Smush.it), .htaccess rules (although W3TC handles gzipping/caching for JS/CSS/HTML which matter the most), and possibly manual optimization of CSS/JS which you covered here.
Anyway, awesome job speeding up your blog that much, under 1 second is outstanding :)
@Antti, thanks for the comment!
It’s good to see such passion and devotion to W3 Total Cache. That alone makes me want to switch to it.
Maybe once my current traffic spike subsides. It’s worth noting that it does require PHP5+. Thankfully I fit those requirements.
Further awesomeness can be had using nginx as the web server.
My favorite setup (I haven’t pulled it off yet in production, to be honest) is to make WP write static files out (some of the caching plugins do this) and then have nginx serve them.
In this setup, only cache misses (which you can store in memory with memcached) are sent to apache+php+mysql (which runs behind nginx) — nearly all the traffic is served from static files, which are crazy fast. Reference: http://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/
I’ve also run WP 2.9 directly on nginx and it’s very, very speedy. But you lose apache’s modules, which means for a lot of configuring and compiling php by hand. Or maybe I wasn’t clever enough to figure out how to do it with the package manager. I switched back to get GD running again.
Anyway, very good tips! Thanks.
Also — if you’re serving libraries from a big CDN (like Google), they’re very likely cached.
I <3 nginx. I had the pleasure of working with it on The Design Cubicle. It’s super fast by default. I did, however, manage to whitescreen and crash the server a few times trying to get a similar config working. I might get an nginx box going soon and revisit and see if i can get it working faster sans breaking it :)
Yes I also think that W3 Total Cache is better.
And if you want to use opcode cache it’s really faster than normal disk caching.
Good writeup, I found a lot of those tips worked well. A common one that often gives good results is the modifying of .htaccess for caching/zipping.
I guess it works ok for a site of this sort and wordpress sites in general. I’ve done it on a wp site of mine and bought the yslow score up as high as 89 but there’s a careful balance to be struck in not getting too carried away and optimising every last m/sec at the expense of more “useful” development time!
It’s very easy to get carried away as I found one late night!
Not to be lazy but every front-end developer should be doing this. Shouldn’t there be a build process to automate a a lot of this?
Tried to use almost all of your tips, and now my blog is really faster! GZIP compression was not very clear before for me, but now everything is fine and loads faster. :)
Superb article!
One knows it all will finally make the move by taking your article as a checklist.
Bravo, great article, and a nice summary of Steve Souders “High Performance Web Sites” book adapted to WordPress sites. I’m surprised though by the size reduction you achieved with the CSS minification. Usually I get between 20% and 40% top size reduction. But it’s true WordPress stylesheets are quite long and not always efficient.
I wrote a post specifically on CSS minification explaining it’s principle:
http://p6ril.wordpress.com/2010/06/30/minify-your-css-files-speed-and-other-seo-wizardry/
Last comment: amazing time load reduction in the end, but it only applies to a site which has already been visited (so browser cache can be used). As Steve Souders mentions, most users have an empty cache (1st visit situation).
Thanks for the read I’ve bookmarked your post for future reference.
Real nice. In the process of building a site and was performing the same tedious tasks of finding best optimization methods and resources. Lucky for me, you did it already. Back to work. Thx.
Thank you so much for this. This was a really good outline for what I needed to do. Not sure how fast my website is now, but it is a hell of a lot faster than before.
i’m going to say that this is probably the best blog article i’ve ever read. honestly.
i do feel sad for anyone who skipped to the end, but how could anyone? well written, thorough, and worth every minute of my time.
i’m glad i now have a new bookmark.
:) thanks!
This is a well-done article, thanks for writing it.
Thanks, Matt! That means a lot coming from you. Really appreciate the work you and core contributors do for WordPress.
I will be referencing this, thank you!
I had gone through a lot of optimization when I stumbled across a file (for a page background) that was unecessarily large. While Smushit and other similar services can reduce file size, they are lossless. This is a GOOD thing, actually, but you have to be careful.
I found that changing the output settings of the original file, as well as optimizing the way the image was tiling, shaved a full 2 seconds off my load time. It was the single biggest improvement I made!
The moral of the story: yes, absolutely optimize all of this. But when it comes to images, start with the smallest possible file to begin with (in terms of your comfort at compression artifacts or optimized palettes if applicable). Then Smushit some more. Along with reducing HTTP requests, this will be your biggest way to gain performance benefits.
Hi davatron5000,
Great article, i love it! :)
I have one request.
I’m writing Turkish WordPress support blog, there is: http://www.wpdestek.com .
And I want to translate all of this article. Then publish in my blog.
I think, this article will be very helpful for Turkish bloggers.
Can I translate and publish it?
I’m waiting your answer. Thanks.
Tufan,
Please! Go ahead and translate! All I ask is for a link back to my site, the original article.
Sağ olun
Thanks Dave.
I will inform you after publish.
Great tools, I can’t wait to start making improvements on my sites.
I’m a little scared to check their load times though, they might be pretty horrible right now!
Chris! Make it happ’n, Cap’n! It’s pretty great once you get your head around it.
I must said that I’m enjoying reading this carefully from the start till end.
Help me a lot for my understanding in web performance!
Great article!
Hi Dave, nice one – there is a way to remove surplus code and still ease the updating pain- once you’ve identified the culprit lines in the plugin files you can use wp_deregister_script and remove_action in your functions.php file to nuke them.
Justin Tadlock’s got more on deregister_script here: http://justintadlock.com/archives/2009/08/06/how-to-disable-scripts-and-styles
Cheers
Awesome! Thanks for mentioning that! I’m going to cover some of that in another article (as well as how to disable my dribbble plugin if you need to). but thanks for mentioning that on here! i might need to update this article soon :)
thank you for bringing all that together in one useful article!
Thank you, Albert! Let us all know how it works out for you.
Great article Dave, thanks a lot! :)
I was wondering if the caching of JavaScripts also applies to things like Google Analytics on your page? This is one of the reasons which kept me from going further into caching…
Cheers,
Lars.
Great article…
thank you for sharing… :D
Great Article. Will definitely apply some of these techniques. (:
Some good tips here for even non-wordpress sites.
I made it also on my wbesite and gain a lot, not only for productivity but also for user experience !
Imho, it’s good to replace image gradients and shadows with CSS3. They are not really critical for site, but may reduce loading times significant.
Your biggest gains were in image optimization and caching.
thanks for benchmark numbers, very helpful.
This is an awesome tutorial, i’ve tried almost half of them, the ones that i haven’t figured out is gzip browser cache.
Thanks for bringing this up :)
excellent post mate bookmarked :)
Thank you for this detailed write-up! I had a quick quesion, and maybe this is just an oddity based on where I’m located (NorCal). I ran pagespeed on your homepage and your site scored 94 points out of 100. Then, I ran pagespeed on Paravel and that scored 89 points. For some reason, however, Paravel just pops right away — even with all the big images — and your own homepage has a little lag in comparison. Do you think it’s a WordPress vs. custom site, or more hardware-related (better server)? If it is WP-related, would you recommend moving that installation into a subdirectory/subdomain to further make the site snappier? Would love to hear your thoughts.
Good sleuthing, Mike.
I tested out what you’re saying, and you’re right! Paravel does load faster on average. http://whichloadsfaster.com/?l=paravelinc.com&r=daverupert.com×=5
This is really interesting. The Paravel server is actually slower hardware all around and a much older PHP install. AND, as you can see by the Page Speed score, the Paravel site still has a ways to go in optimizing, I just spent a lunch hour on it.
I’m now in full MythBusters Mode and have a few plausible explanations for this:
Sorry i’m not able to bust this myth. But you’ve got my gears turning and i just spent like an hour looking at the NET panel in firebug.
As far as moving your WP install to a subdirectory, i’d probably recommend against that, since that’d be another DNS lookup, but rather, move your image/js/css assets over to a separate CDN. That would probably yield a greater boost.
Hope that helps.
Have you tried webo speedup for WordPress? I’ve tried it on mine and I’ve found that it uses a lot of the techniques you described above. I had to mess with it for a while to find a setting that didn’t break my page. Also, you might want to take a look at cloudflare.com. It’s supposed to be a free CDN, and minimizes the number of malicious requests. Worth a try at the price of free.
Thanks Dave! Yeah, I was considering Amazon S3 for a while, but I wasn’t sure about the costs. Their pricing calculator is a tad over my head with the gazillion options you can input. Plus, I got weary about the fact that you can’t *really* FTP into your directories — there’s a FF add-on that I saw that could kind of do it, but I read that it crapped out occasionally. And I wasn’t sure how to handle migrations either, in terms of file uploads/downloads (I’m running WP with VaultPress, so I don’t know if/how they could keep a copy of my uploads). Got insight to this by any chance?
Amazon S3 is a pretty good dumping ground for media assets. I’d recommend uploading everything through blog related through the Media Library and using a plugin to route that to your S3 folder http://wordpress.org/extend/plugins/tantan-s3/ Using Amazon as your CDN would definitely speed up your blog.
As far as how VaultPress works, I’m not totally sure because I haven’t used it, but congrats on getting a golden ticket! :) But try that plugin and let me know if it works. If it does, I might move some assets from the ATX Web Show and this blog over to it.
Wow, Joe Tan! I remember using one of his plugins back in the day. Perusing through description and the forums, this seems exactly what I’m looking for. Will give this a try when I have some spare mula again — just spent a bunch on plugins/hosting, heh. Hey, is there any way to contact you directly other than through the comments? I had a question that I’d rather ask via email/chat/phone/pigeon mail.
Some hosts don’t support mod_deflate and such, making it difficult to do gzip in that fashion. However, I found a simple workaround that can help with compressing individual problem files.
This code targets JS files. Add it to the top of the .htaccess:
# handle gzipped js files
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !”.*Safari.*”
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*) $1.gz [L,QSA]
AddEncoding x-gzip .gz
Header set Content-Encoding: gzip
ForceType text/javascript
Then, for any large JS files, merely gzip them and put the resulting .js.gz file in the same directory as the .js file. The rewrite code will serve the compressed version instead for browsers that support it.
Note: The previous code should have been:
# handle gzipped js filesRewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP:Accept-encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*) $1.gz [L,QSA]
<Files *.js.gz="">
AddEncoding x-gzip .gz
Header set Content-Encoding: gzip
ForceType text/javascript
</Files>
Comment ate the “< " and ">” signs.
Nice! I wish more people would focus on speed optimization!
Hi Dave,
You mentioned the following –
“I’m actually using W3 on my site now. I have a few mixed feelings about it, but it’s alright.”
I use W3 on my site too. I am frustrated that YSlow will not recognize Gzip compression or Expires headers on my site. I use a self hosted WordPress blog on a shared server and the Atahualpa theme. If I check my site on other web tools (http://www.gidnetwork.com/tools/gzip-test.php) I get the response that both of these items are enabled, in use and working correctly.
I was wondering if you have encountered any issues like this and what you did about them if anything? If I try and add to my htaccess file my blog goes to a white screen. Reverse the htaccess changes and it is back. So I too have a few mixed feelings about W3 Total Cache.
Great article! Thanks for sharing.
Trish
I noticed it could take as long as ~24 hours for the YSlow to recognize. It’s frustrating but it eventually updates.
Re: Whitescreening: W3 Total Cache does all the htaccess stuff for you. I wouldn’t mix the code in this post that one. I may do a followup post on things I’ve learned using W3TotalCache. Good luck.
One more tool
works with any browser, even on my ancient laptop with ie6
http://siteloadtest.com
Great info and straight to the point. I am not sure if this is truly the best place to ask but do you people have any thoughts on where to hire some professional writers? Thanks :)
If i grade my site with yslow i get a overall performance score of 92 for a small site, i can not gzip as my hosting does not allow it, however great article and i will try WP super cache, thanks!
This is so incredible and helpful. Thank you!
I posted one more comment to your blog, but you didnt approve that. I still keep check your blog anyways..
Great tips and article on tips to optimizing for speed for website downloading to increase performance and SEO.
I’ve done alot of the things you’ve mentioned but found your sprite recommendations to be very helpful.
Will try out that .htaccess script as well; I’ve had one which was called the “holy .htaccess” script; wonder if its similar.
Who do you recommend for WordPress hosting? I’ve used MediaTemple and Webfaction. Webfaction is definitely faster, but I’m wondering if there is a “best” host for WordPress performance.
Good question, but it sort of depends. We’ve been using a mediaTemple (Dv) server for a long long time, just got another one. I wouldn’t recommend the (gs) server unless you’re hosting just one blog.
WPEngine is the fastest, most secure serverI know of and is tuned expressly for WordPress. It’s ~$50/mo, which is expensive, but I’ve always been of the opinion that you get what you pay for with hosting.
Awesome content. I love your method and your writing style. Made reading very enjoyable. Very useful. Bookmarked for future.
W3 Total Cache will do the minification and concatenation of your CSS and JS files for you, as well as all of the caching. It will also help you get set up automatically on a CDN.
One word…BOOKMARKED!
Awesome post. Can’t wait to try some of these out on some client sites. Keep up the fantastic work.