Amazon Silk and Performance Responsibility

Posted: December 16, 2011 at 7:49 pm

Now that Amazon’s Kindle Fire tablet is making its way into customers hands we are starting to hear about how its much touted Silk web browser and its web acceleration feature functions in real life. Initial research shows that, at least in this 1.0 release, Silk is actually faster with acceleration turned off.

I don’t want to focus on how good or bad Silk’s acceleration feature is. Technology only gets better. I agree with Steve Souders that Silk will eventually provide a faster browsing experience. Making Silk’s acceleration work is a technical issue which Amazon can solve. Instead I want to focus on the larger policy issue: Who is responsible for web performance?

With Silk, Amazon is telling web developers that they suck at making fast sites. In fact, they suck so much, that Amazon is not going to wait for them to stop sucking. Instead Amazon has taken the unprecedented step to proxy all of the web traffic of Silk users and apply performance optimizations on the fly. Its mod_pagespeed, but in reverse.

The traditional view is that it’s the website owners’ responsibility to make a website faster. But Amazon is saying “its the creator of the consumption device’s responsibility to make a website faster.

That’s pretty startling shift in view.

A bunny insulting you

Amazon has made a business decision that the Kindle Fire will provide the fastest tablet browsing experience possible. (Sound familiar?) To ensure this happens, Amazon developed its own web browser and is spending millions of dollars on the infrastructure to support this acceleration feature. Web server does not support SPDY? Solved. Website not using compression? Solved. Content not minifed? Solved. But only if you are using a Kindle Fire.

In other words, web performance is so poor that hardware vendors are able differentiate themselves by solving your website’s performance problems.

It’s not surprising that Amazon decided to take matters into its own hands I have written extensively and presented Zoompf’s research at Velocity numerous times on the matter. 70% of images aren’t losslessly optimized. 75% of sites have an item which should have HTTP compression which doesn’t. 30% of webpages contain errors. Even Twitter is choking on implementing some of the most basic of optimizations. It’s not pretty out there.

But is it really a 3rd party, be it a online retailer, a consumer electronics company, a network device manufacturer, or a software vendor, who magically absolves you of the responsibility to make a fast site? This is an interesting question.

I am of the opinion that it is the web app creator’s responsibility to make it fast. In fact, the entire philosophy of Zoompf is, ultimately, web performance transparency: Scan my site; tell me specifically what the performance problems are; tell me how severe they are and what their impact is; show me how to fix them with configuration, process, and code changes; validate they get fixed; monitor and track that they are not re-introduced. No magic. No obfuscation. No “trust us, performance is hard, we got this, pay no attention to the man behind the curtain.” Just data, and the tools and guidance to make informed decisions.

Who is responsible for web performance? Who do you think? This question that will play out over the next several years and I’ll write more of my thoughts soon.

Zoompf Releases Industry Report and Launches Zoompf WPO

Posted: June 21, 2010 at 5:28 pm

Today we have two exciting announcements with Zoompf.

2010 State of Web Performance Report

Our first announcement is the release of our 2010 State of Web Performance report. Zoompf used our technology to assess the Alexa Top 1000 for performance defects to determine how well they have implemented proven web performance optimization techniques. Our research shows that even the largest sites on the web have trouble implementing even the most basic of performance optimization. Just consider lossless optimizations like HTTP compression, minification, and image crunching. Zoompf found that had these optimizations been properly implemented, there would be a 20% reduction in bandwidth across the entire Alexa Top 1000. This is a startling number. 1 byte of our every 5 bytes of web traffic is wasted bloat that can be eliminated using common performance optimizations, some of which are over a decade old!

There are way too many findings to reveal them all here. The 2010 State of Web Performance report is over 25 pages long and is packed full of statistics, analysis, and advice on how organizations can learn from the successes and failures of the Alexa Top 1000. Download your free copy now.

Download Zoompf’s 2010 State of Web Performance report.

I will be presenting results and highlights from our 2010 State of Web Performance at the Velocity Conference Tuesday night at the Ignite Sessions. If you are attending come watch a humorous trek through 90,000 URLs of content!

New Product Offering

Our second announcement is that today Zoompf launches a new product: Zoompf Web Performance Optimizer (WPO). Zoompf WPO is a web-based SaaS that allows you to assess any web application for over 300 different performance issues, from anywhere, at anytime. Zoompf WPO goes beyond our free performance assessment in several key ways:

  • Coverage: Zoompf WPO Scans your entire application for performance problems.
  • Depth: Zoompf WPO tests your app for over 300 problems and provides comprehensive information about each issue. Users receive details about each problem and its causes, complete with graphs and diagrams, as well as full remediation advice including configuration settings, code snippets, and implementation best practices.
  • Root Cause: Zoompf WPO allows you to drill down into any performance issues and highlights the text or code in a response that is causing the performance problem.
  • Rich Reports: Zoompf WPO offers 10 different reports to help you understand the issues and the impact of your changes. WPO also generates prioritized action plans, so you know exactly what IT operations or the designers should work on first to get the biggest improvement.
  • Assessment History: Zoompf WPO keeps track of all your past performance assessments. This allows you to measure and track performance defects across the entire the development and deployment of the application.

Pricing for Zoompf WPO starts at just $99 a month and is available now. Learn more about Zoompf WPO.

We extremely excited and proud to launch our Zoompf Web Performance Optimizer product and release this groundbreaking industry report. Our mission at Zoompf is to enabled web designers, web developers, and IT operations to build fast web applications. The addition of Zoompf WPO to our existing free web performance scanning service and our professional services provides an entire suite of performance products and services to fulfill this mission. I encourage you to take a look at our web performance products and services today and see how Zoompf can help you.

If you are attending the Velocity conference drop by and say hello, or reach out to us for a face-to-face meeting. You can contact us on twitter (@zoompf), through email (info@zoompf.com) or call us at 1-404-414-2000.

What’s Your Website’s Performance Rank?

Posted: May 26, 2010 at 8:11 pm

Lord Kelvin, the famous British scientist and mathematician, once said: “You cannot improve what you cannot measure.” Just as web developers track the quality of their code using unit testing, regression suites, and bug trackers to improve their work, performance metrics are needed as well.

So we created the Zoompf Performance Rank. This rank easily quantifies the performance status of your website. You can compare Performance Rank across different sites, or track how the performance of the same site varies over time.

photo of a score board

Zoompf’s Performance Rank for a website is calculated by scoring each response individually on a scale from 0 to 100. The score of all the responses are averaged together to yield the Zoompf Performance Rank . If a response has no performance problems it scores 100 points. For every performance problem a resource has points are deducted from that resource’s score. The number of points deducted is based on the severity of the performance issue. Critical defects, like not HTTP compression for a compressable response subtract 25 points.High severity issues like Unoptimized images are 15 points. The lowest score any resource can have is a 0. This only happens if the page has a large number of performance issues. No page will have a score less than zero. This means if your website only consists of 2 pages, one that is completely awful and the other is perfect, the lowest Performance Rank you can have is 50, regardless of how awful that awful page is.

Zoompf Performance Rank is a very flexible scoring system that more accurately reflects the performance of a site than other scoring systems. Let’s say you run a photography site that consists of 1 HTML page and 19 images. Let’s say you don’t have HTTP compression turned on so your HTML page receives a score of 75 while the images have no problems and each receive a score of 100. The Zoompf Performance Rank would be 98.75. Other tools might take off a large number of points because such a critical issue as HTTP compression is not turned on. However for this photography site, HTTP compression is not a big concern. The vast majority of the site, both in bandwidth and page count, would not benefit from HTTP compression. Now consider the same photography site. HTTP compression is now turned on for the HTML page (100 points), but all of the images are unoptimized (85 points each). The Zoompf Performance Rank is 85.75. Even though the performance problem is less severe, it affects the vast majority of the photography website and so has a lower Zoompf Performance Rank.

You can find our your Zoompf Performance Rank and test your website for over 300 performance issues right now using our free web performance scanning service. We also setup a Twitter account for the performance scanner (@zoompfauto) which tweets out the Performance Rank and a link to the full Zoompf performance report for every werbsite it scans. This is a great way to see how your site compares with others. As always feedback and questions are always welcome. Enjoy!

6 Crazy Weeks and New Online Web Performance Service

Posted: April 12, 2010 at 2:11 pm

The last 6 weeks have been a very exciting time for us at Zoompf. 5 weeks ago we passed the 300 check mark for issues we test your website for using our performance scanning technology. Next we went live with a brand new web design and content management system to manage all our online content and make it easier for you to find the latest front-end performance techniques on our site and on our blog.

Less than 1 month ago, we rolled out our free 100% fully automated web performance scanner. This free service would scan whatever website you want, whenever you want, and as often as you want, and email you a web performance optimization report offering clear guidance to make you website blazingly fast. Since then over 400 submitted their email and received a free scan. Then we introduced of our web performance scanning bookmarklet which allowed anyone to check whatever site they were browsing for web performance problems regardless of what web browser or operating system they were using. This milestone made it even easier to use Zoompf’s performance scanning technology and discover how Zoompf can help web developers, designers and IT professionals build faster sites!

Shortcomings Abound

Of course to get a free performance assessment you still had to type in an email address. This was a barrier for some people. Creating the report and delivering it also wasn’t pretty. It could take up to several minutes before you would receive you report. And when you did receive the performance report is was a ZIP file containing some HTML and supporting images. Very cumbersome indeed! All of these factors made it difficult for web developers, designers, and front-end engineers to seamlessly integrate Zoompf’s performance analysis into their everyday workflow or tool chain.

Well our goal is to provide free tools, software, and services to help make the web a faster place. And that won’t happen unless it is completely painless to use Zoompf during your daily grind. So we all emptied our wallets, rolled some loose coins, and sold our bodies on the 14th hole of Augusta National’s golf course to purchase a crazy fast computer to replace our aging scanning box. Now Zoompf performance scans take seconds instead of minutes. Next, we slaved through the nights, hacking code to remove the entire email dependency from our scanning system and wrote an online reporting system.

Like Awesome in a can!

That’s right, today we are happy to announce our free performance scanning service is now entirely online! No email address, nothing to install, just sweet web-based performance checking honey. Punch in any URL you want scanned into the system, mash on “go” and in seconds you will be seeing a Zoompf performance report right inside your browser! Doc even made it work on iPhones or IE6 ;-) It looks something like this:

Screen shot of online Zoompf scanning service reports

(O’Reilly’s woodcut animal‘s eyes are so wide because he’s surprised by the wide range of web performance problems on oreilly.com!)

Now for the cool news. Not sure if you noticed but we actually flipped the switch turned activated the online service very late Friday night/very early Saturday morning (approximately 1:45am EST on April 10th). We are very pleased to say that in the last 55 hours or so, people from around the global have used Zoompf to test the performance of over 800 websites!

Want to try it out? Simply go to zoompf.com/free, type in a URL, and bask in awesomeness of free, comprehensive web performance optimization reports! Help us try and get over 1000 scans in the first 72 hours!

Recap

  • We just launch 100% free, 100% online web performance scanning service
  • We check your app for over 300 different performance and website issues
  • o strings! No email required. Unlimited use. No silly technical prejudices. Any browser. Any OS. Period.

On behalf of the entire Zoompf team, myself, Doc, JR, Tracy, and Brian, we thank you for the bottom of our hearts for your interest, feedback and support. It’s going to be an amazing year as we continue to make Zoompf the source to help your find and fix web performance optimization problems.

Enjoy,

Billy Hoffamn. Zoompf Founder

Free Performance Scanning Service and New Web Design

Posted: March 16, 2010 at 11:21 pm

We have two big announcements for you all today.

The first announcement is that we have finished rolling out a complete web design for Zoompf.com. The awesome folks over at Zero G Creative did the design and we worked with them to get everything tweaked (include the Sisyphean task of making everything look pretty even in dead browsers like IE6) and to hook it into our new backend systems. We are very pleased with the results and we will be implementing addition changes in the coming weeks.If you run into any issues please let us know.

We are very proud of our second announcement. Today we are unveiling Zoompf’s new automated web performance scanning service. Simply plug in a URL and we scan your website for over 300 performance issues and then email you a pretty report in minutes. It’s completely free, so please use it as much as you’d like and as often as you’d like. We are experimenting with new features, such as PDF reports, load graphs, resource hierarchy graphs, and other cool features and will keep you posted.

For now enjoy the new Zoompf website and take your favorite websites for a spin with our free web performance scanning service!

Useless Duplicate Cookies

Posted: March 8, 2010 at 1:58 pm

In our last post where we described the 300 issues Zoompf checks your website for during its web performance asessment we said that the #1 way we discover new web performance issues is simply looking at web responses. This story is a perfect example of how that actually happens. Today (in fact, about 2 hours ago) we were helping a client optimize their site when we noticed a rather long HTTP Set-Cookie header. This is what we saw:

Now that is rather difficult to look at. So we cleaned up the code, trimmed out the expires and path information for each cookie declaration, and aligned each cookie name/value pair on its own line. This is the clean version:

Set-Cookie:
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],
cisession=a%3A4%3A%7Bs%3A10%3A%22session_id... [snip],

As you can see, the web application is setting the cisession cookie 9 separate times! And every time it gets set to the very same value. Now each distinct cookie name can only have one value. The web browser will use the last declaration. So this response needlessly sets the cookie 8 times. The original Set-Cookie header’s value was 3681 bytes long. But when you remove the first 8 cisession cookie declarations and instead only have 1 cisession cookie that size is reduce to 409 bytes, a reduction of 89%.

Well that’s a nice find. But then things got worse. This site used rotating cookie values where the value of the cookie is changes on each and every page (this is often done in banking and e-commerce applications to mitigate session hijacking). In this case that meant every page generated by PHP hadthese 9 cookie declarations. By identifying and resolving this problem we helped the client take 3 kilobytes of every HTML response! Now that’s a really nice performance optimization!

Cause of the Issue

This client had an online store. To uniquely identify each visitor and provide them with a shopping cart the application code had to set a session identifier for the visitor. They had a single function which would verify the client had a session identifier and set the new appropriate value. This function was called 9 separate times in different parts of the code during page generation. However the function did not check to see if the session identifier had already been set for this cycle. It just appended on a new cookie declaration. So every time a page was generated, 9 cookie declarations would be added on to the HTTP response.

This issue was hard to detect. Since the browser only uses the last declaration, HTTP requests back to the server only contain 1 cookie, not 9. For the same reason if you use a browser add-on to examine the stored cookies you will only see 1 cookie and not 9. In fact, we had to modify Zoompf’s code to detect this. The System.Net classes in Microsoft .NET were automatically collapsing the 9 redundant cookies into a single cookie. This means our code only saw one cookie as well.

One-off Issue or Plague?

We wanted to see how prevalent the issue of Duplicate Cookies is. So we wrote some quick code and we then re-analyzed approximately 700 web performance scans we have already performed on other websites to see who else had the issue. We found 16 other websites, or around 2.5% of websites we had assessed had this issue. While it is by no means as common an issue as say Images without any caching information (Check #172) we were surprised at how common the issue is. Spot checking those 16 website shows the same fundamental issue: the same cookie getting set to the same value multiple times in a single HTTP response. Again, this is most likely caused by repeated execution of the same function or code path which sets the cookie value.

Since it is a fairly easy mistake to make and is not a one-off issue, we decided to promote this to a full fledged performance check. So we wrote Zoompf check: #316: Duplicate Cookies to detect this issue.

Want to see what performance problems your website has? Duplicate Cookies is just two of the 300+ web performance issues Zoompf detects when scanning your web applications. Get your instant free web performance assessment at Zoompf.com today!

Zoompf Check #300! Or: Gateway’s got a problem…

Posted: March 4, 2010 at 3:17 pm

People often ask how we discover new performance issues. Without a doubt the #1 way we discover new issues is simply by looking at websites and seeing how they work. Not a customer engagement goes by where we don’t find at least one new web performance issue that we add to our growing database of web performance issues. This why Zoompf has added over 150 performance checks since we went public with our offerings. In this blog post we are going to give you the back story around a cool performance problem we found. In fact, it was so interesting and impact it became our 300th check in our database of web performance issues!

Picture of a cork popping out of a bottle

The Strange Case of CSS Resources

We recently made a few changes to our CSS parser and we were testing the new features against a few dozen pages to ensure we hadn’t broken anything. While testing, we noticed something odd on Gateway’s website. All of the background images in one of the style sheets for gateway.com were served over an encrypted SSL connection. In other words, the style sheet http://www.gateway.com/css/cms/styles.css is served over a plain unencrypted HTTP connection. However it includes links to background images like https://cdn.gateway.com/media/cphp/themes/default_bg.gif which are served over an encrypted SSL connection. What’s odd is the web server will serve those background images just fine if you request them using HTTP instead of HTTPs. It’s even weirder since very little of Gateway’s website even uses SSL. In fact, trying to access the root of the Gateway’s website using HTTPS will redirect you to the HTTP version.

So, certainly something weird, but is this a performance issue? After all, the developers just added a few extra “s” characters to their CSS. So what if maybe a little bit of SSL gets used. What are the performance implications of that?

Actually, they are huge!

SSL Primer

HTTPS is HTTP traffic sent over an encrypted SSL tunnel. SSL is expensive for 2 reasons (documented here and here). The first is the SSL handshake, where it is negotiated between the client and the server what protocols will be used and keys are exchanged. This involves the use of asymmetric key encryption with is extremely math heavy and quite slow. Then there is bulk data encryption, which is where the server is using symmetric key encryption. Symmetric key encryption is much faster than asymmetric key encryption, but can be much slower than sending unencrypted data. (How much slower is beyond the scope of this article. Suffice it to say that the performance impact of SSL is sufficiently large that there is an entire market for SSL acceleration products).

So what’s the impact in this situation? Well, the extremely expensive initial SSL negotiation must be done for the two initial connections to the web server. Each of these negotiations takes between 250 milliseconds to 350 milliseconds. This is in addition to the overhead of making the TCP connection and the negative impact of TCP’s Slow start and congestion control. Even reusing pre-negotiated keys a connection close is expensive, typically costing between 60 milliseconds and 100 milliseconds.

The Performance Impact

That doesn’t sound too bad but see how it affects Gateway. Examining this waterfall graph for www.gateway.com shows that 1.5 seconds, or over 25% of the page load time for Gateway.com, is due to the overhead of SSL! It’s hard to believe but the simple additional of 14 “s” characters to the page caused 1.5 seconds of delay! Further more Gateway’s web server is going to be working about twice as hard to push encrypt and serve those resources! Server load, power, cooling, and availability are all adversely affected.

(Notice there are a lot of other problems with Gateway’s website that contributed to the damage the SSL issue caused. Specifically they were not using persistent connection which caused a dozen of the smaller re-use negotiations to occur. Luckily Zoompf Check #177 and #178 detected all these closed persistent connections!).

Wow. So how did this happen? It could be for a lot of reasons, all of them fairly simple to make or innocent. It could have been a simple typo. It could have been left over from a redesign where that style sheet was used exclusively inside of the SSL portion of the site. It could be that this style sheet is used in both the SSL and non-SSL portions of the site, but to avoid a mixed content warning, the resources are referenced using SSL. The solution to this is simple. The style sheet should use protocol relative URLs to reference the images. That way if the style site is in the SSL portion of the website (and referenced using an https URL) the background images will requested using HTTPS. And when the style sheet is in the non-SSL portion of the website (and referenced using an http URL) the background images will be requested using HTTP.

It is both cool and scary that such a simple issue can have huge performance implications. And unfortunately none of the free tools like YSlow or PageSpeed would have alerted you to the issue. Until now.

It is with great pleasure and pride that we announce Zoompf Check #300: SSL Resources on Non-SSL Page. That this is such a simple issue to have and at the same time it causes such as massively negative impact makes it worthy to be our 300th check.

Want to see what performance problems your website has? Finding SSL Resource on Non-SSL pagesis just one of the 300 issues Zoompf detects when analyzing your web applications. Get your instant free mini web performance assessment at Zoompf.com today!

Top PNG Optimizers Don't Use zlib

Posted: January 5, 2010 at 12:26 pm

Oleg Kikin has an interesting chart comparing the performance multiple different PNG optimizing tools. The tools tested are:

Go take a look at the PNG comparison chart. I can wait.

So what do these results mean? Well I believe it shows how far image optimization has come in the last 2 years. Tools that just manipulate the parameters for the stock DEFLATE compressor code that is included in the zlib compression library and remove extra PNG chunks no longer produce the smallest optimized image. PNGOut and AdvanceCOMP produce the smallest PNGs because they use custom DEFLATE compressors that achieve better compression than zlib’s implementation. PNGOut’s deflate compressor was written from scratch and AdvanceCOMP uses the custom DEFLATE compressor written for 7Zip. We’ve talked about 7Zip and DEFLATE before in the Rezipping Web Resources for Fun and Profit post. I used 7Zip for my rezipping work because it’s optimized DEFLATE compressor compresses data better than the DEFLATE compressor in zlib. This in turn produces smaller ZIP files but the logic applies to image formats that use DEFLATE.

Unfortunately I cannot find any information about the command line options Oleg used with each tool.

It is interesting to note the difference between Smush.it and PNGCrush. According to Smush.it’s information page it is using PNGcrush under the covers. Any difference in the output of Smush.it and PNGCrush is entirely from the command line options that we know nothing about. It would be possible to reverse engineer what Smush.it is doing by using the service and comparing the output. I image they are using the -m option instead of the -brute option to reduce the number of rounds of PNGCrush and improve the response speed of the Smush.it web service.

What we really need is a web service that accepts images and tries several different optimization tools. Smush.it has hinted at this for a while now in their FAQ but improvements to the tool seem to have stalled since Yahoo took it over (to say nothing of the un-sexy-fying of the Smush.it UI). Hopefully something like this will appear.

Want to see what performance problems you have? Unoptimized PNG images are just one of the 200+ performance issues Zoompf detects while assessing your web applications. You can sign up for a free mini web performance assessment at Zoompf.com today!

Browser Performance Problem with CSS "print" Media Type

Posted: December 7, 2009 at 3:02 pm

I ran across an article today that shocked me. Geert De Deckere wrote how you can save an HTTP request by combining the CSS files for the print and screen media types.

Wait, I thought. What? Why do I need to do this? What behavior is this correcting? I was very confused. Maybe you are too.

image of CSS code in an editor

CSS allows you to define styling information for different media types. CSS could tell a browser that is rendering to a TV screen to style the same content differently from a browser rendering on a mobile phone. The HTML content is all the same. Media types simply define which style rules apply for which devices. CSS also defines a print media type which is the style to use when styling a page that is being printed. Browsers should be smart about only downloading the style sheet with the media type for the device they are rendering. Firefox on my laptop is should not fetch the mobile.css style sheet whose media type is handheld. And luckily browsers are smart and don’t download CSS files for media types that they don’t support.

Except for the CSS media type print.

Geert’s article and advice were predicated on the claim that web browsers will download external style sheets with the print media type even if you don’t print the page. Is this true? To find out I built a quick test page:

<html> <head> <title>CSS Media Tests</title> <link rel="stylesheet" type="text/css" href="screen.css" media="screen" /> <link rel="stylesheet" type="text/css" href="print.css" media="print" /> </head> <p> Hello! <img src="new-logo.png"> </p> </html>

Wow! Geert’s claim was true! All major desktop browsers that I tested (Firefox 3.5, IE 7, Chrome 3.0 and Safari 4.0) will download external style sheets whose media type is print even if you don’t print the page! This is hurts performance for no good reason. Currently your browser must make one HTTP request and download screen.css. But then your browser has to make an additional HTTP request to download a file full of content that it does not need. Worst of all, the browser will not start rendering the page until it has grabbed the completely unused print.css file!

This is very silly behavior. Especially given that virtually none of your website visitors are going to print any of your web pages, unless you are a website like Google Maps. Try and remember: “when was the last time your printed a web page?” Unfortunately all 4 browser I tested all downloaded print.css even though I never printed the page. Firefox, IE, and Chrome all downloaded print.css in order as if it was a external CSS file whose media type was screen. Looking through a proxy the request order was:

  1. css-media-test.html
  2. screen.css
  3. print.css
  4. new-logo.png

Safari 4.0 however, downloaded the content in this order:

  1. css-media-test.html
  2. screen.css
  3. new-logo.png
  4. print.css

Safari was smart enough to defer downloading but did still downloaded it. I do not know if Safari delayed firing the window.onload event until after print.css downloaded or not. WebPageTest confirms that IE does not start rendering the page until print.css is downloaded. The fact that Firefox and Chrome both requested content in the same order as IE leads me to think they also delay rendering.

Possible Solution?

Geert proposed a solution to this problem. He recommends combining the two external CSS files into a single CSS file and use @media directives inside the CSS file to separate the style info for screen from the style info for print. You end up with a single CSS file that looks like this

@media screen { /* contents of screen.css here */ } @media print { /* contents of print.css here */ }

This solution does not sit well with me. Yes, by combining the two CSS files and using @media directives you can remove an HTTP request. You now only have to download a single CSS file whose size will be smaller than the sum of the two original file sizes because a single large file will compress better. However your visitors still have to download a large amount of CSS content. 30-40% of that content is printer-centric style information which no one will ever actually use anyway, and the browser will not start to render the page until all this useless data has been downloaded. (Interestingly enough Zoompf free Web Performance Scan checks style blocks and CSS files for @media directives and recommends you break them into separate style sheets to prevent unnecessary rules from being downloaded. I had to modify the check to allow @media print directives when I found this solution.)

A Different Solution

I believe there is a different and perhaps better solution. You can defer downloading print.css by using JavaScript to dynamically add a <LINK> tag pointing to the external CSS file with the print media type after the page has loaded! This solution means the browser only needs to make 1 HTTP request and less CSS content needs to be downloaded to start drawing the page. This will have a faster “Time to Render” than a single CSS file as less data is downloaded. The extremely small number of people who do print your web page will still get the style sheet necessary for them to print. You can also use a <NOSCRIPT> tag in the <HEAD> to link to print.css. This means anyone who has JavaScript turned off will the performance hit all of your visitors are currently taking and request both external style sheets. The deferring print.css solution looks like this:

<html> <head> <title>CSS Media Tests</title> <link rel="stylesheet" type="text/css" href="screen.css" media="screen" /> <noscript> <link rel="stylesheet" type="text/css" href="print.css" media="print" /> </noscript> </head> <p> Hello! <img src="new-logo.png"> </p> <script> window.onload = function() { var cssNode = document.createElement('link'); cssNode.type = 'text/css'; cssNode.rel = 'stylesheet'; cssNode.href = 'print.css'; cssNode.media = 'print'; document.getElementsByTagName("head")[0].appendChild(cssNode); } </script> </html>

You reduce initial request count and download size at the cost of greater complexity and more markup. This code could be improved. A more scalable solution would be for the JavaScript code to look in the <HEAD> and parse any <LINK> tags inside of a <NOSCRIPT> with a print media type and create new LINK elements dynamically.

Solving the problem

A summary of the problems and the two solutions appears below. This table assumes two CSS files (screen.css and print.css) each 30 kilobytes and size and a combined CSS file (all.css) whose size is 55 kilobytes.

MethodHTTP Requests before “Start Render”CSS Downloaded before “Start Rendering”# HTTP Requests after “Onload”Content Download after “Onload”
No Optimization260 Kb00 Kb
Single CSS file all.css155 Kb00 Kb
Deferring print.css130 Kb130 Kb

Which solution works best will vary with your situtation. The status quo is 2 HTTP requests to deliver 60 Kb of content before the browser can start rendering. A single CSS file reduces that to 1 HTTP requests and 55 Kb of content before the browser can start rendering. Deffering print.css also only requires 1 HTTP request before pageload but only sends 30 Kb before the browser can start rendering. If you have a small print.css file it might be better to use a single CSS file with @media directives. The overhead of serving a single larger CSS file containing unused style dat aand the delay that adds until the browser can start rendering might be so small it does not matter. However if you have a larger print.css file deferring the print.css download until after page load would provide a great performance benefit.

The moral of the story here is that the browser creators need to remove this performance defect from their code. Ideally the print CSS media type data should not be downloaded until the print dialog box appears, either from user action or using window.print() in JavaScript. Next best solution would be for the browser to automatically defer the downloading of “print” CSS media type data until after the page has downloaded. In the mean time, you can use either the single CSS file solution or the deferring print.css solution to make your web pages load faster!

Want to see what performance problems you have? An appropriately placed <LINK> tag and proper use of CSS @media directives are just two of the 200+ performance issues Zoompf detects while assessing your web applications for performance. You can sign up for a free mini web performance assessment at Zoompf.com today!