CloudFlare

 

An All New (and Improved) AutoMinify

Minify

We turned on AutoMinify as a beta feature a while ago, but we weren't particularly happy with it. Originally, we did it the same way everyone else does: we'd request the resource from the origin, serve it unminified on the first load, cache it, and then, if it was CSS or Javascript, run a process that minified it and replaced the cached version on the server. Seems sensible enough, but it's a bad approach.

To begin, this minification strategy doesn't work well for highly dynamic content, forcing website owners to have to go back and expire the cache whenever anything changed. For CSS and Javascript that can work, but it's a disaster for dynamic HTML. The second issue is less obvious: most minification resources don't work at our scale. We tried every minification library available, and a few non-public ones that were developed in-house by friends at some of the Internet giants, and none of them worked as efficiently as we wanted when we're minify many millions of files across twelve (and soon many more) data centers.

We were bummed because minification does provide some measurable benefit. Generally, for text based resources, our tests showed minification got about a 10% benefit when combined with our aggressive GZIP compression over just GZIP compression alone. All else being equal, if you can make a resource 10% as big it's as good as making the Internet connection 10% faster. It's not a huge win, since most bytes that make up the typical website aren't in text-based resources that can be minified. However, we believe every millisecond matters, so we looked for another way.

Unsatisfied with any of the existing minification resources, we decided to develop our own. Last week we quietly turned on a new minification process that was written to overcome the two challenges previous minification strategies had faced. First, it works in-line in the response stream, much like GZIP, which means it doesn't force you to cache content in order to get the benefit. Second, it's extremely fast. Written from the ground up to perform at line speed and is easily 100x as fast as the next closest competitor.

AutoMinify included free with any plan, and you can choose whether you want to minify CSS, Javascipt, HTML (even dynamic HTML), or any combination of the three. You can turn Auto Minify on or off via your CloudFlare Settings control panel with a single click and the settings take effect nearly instantly (because you don't have to wait for the flawed cache-and-store approach). Next up for the engineering wizards behind this: a radically better approach to image optimization.
Posted by Matthew Prince
Views | Favorited 0 Times

Comments (14)

Jun 18, 2011
owen said...
So lemme get this straight; since the cache-and-store approach didn't satisfy your needs, you minify the asset on the fly every time a request is made to that resource?
Jun 18, 2011
Matthew Prince said...
@owen: We intelligently ensure that every request, including the first request, for an actionable resource is minified without slowing down delivery. We definitely take advantage of caching where it makes sense, but it's much like our hyper-optimized GZIP flow. In fact, we wrote the minification engine right into that same flow.
Jun 18, 2011
owen said...
@Matthew: I see, I see.
Jun 18, 2011
Navin said...
i already implemented that on my blog. great job guys
keep it up
Jun 18, 2011
I really like that you guys strive to continue to improve on your technology and infrastructure in a manner that pushes the limits in optimizing content. I think you guys have an amazing road ahead and I would bet a success for your wonderful startup.

I think the key though is going to be partnering with more and more hosting providers (MediaTemple, Laughingsquid, Bluehost, Linode etc.) to get your service used even more widespread. I think in addition to this if you could get some leading sites to use Cloudflare to improve their load times then that will also boost your success. I really would love to see you guys work with AOL on getting their properties to use Cloudflare because Techcrunch & Huffingtonpost which I frequent happen to load at sometimes unbearable speeds.

If you guys can add in some image optimization then I feel like you will have unlocked yet another valuable tool.

Jun 18, 2011
Tuffclassified said...
I am using your minifying features from last 4 days and i really like this feature. I also like your rocket loader but can not use that on my site due to the problem on one page of mine website. It would be great if we have any control to exclude any url for rocket script loader.
Jun 19, 2011
itsdaniel0 said...
Does this update now work with CSS3 Media Quries?
Jun 20, 2011
Tosh said...
I tried this out and it seems to work very well so far. The previous minify you had would break some things on my site. But this new one you created is working great! Keep up the amazing work guys.
Jun 23, 2011
Dan said...
Never really tried the minify option before, or never really noticed anything with it turned on. Will have to go back and try out the improved version of it and see how it works now with a test site.
Jun 23, 2011
BrantTedeschi said...
With HTML minification enabled, shouldn't we see our entire page on one line? Kind of like what w3 total cache does for Wordpress? I am not seeing this behavior, and in fact, don't see any discernable difference when it comes to the HTML and whitespace. Thoughts on this?

@Tuffclassified You can exclude scripts using rocket loader, search the wiki.

Jun 28, 2011
Vincent Mounier said...
Hi Matthew,

Almost one week using the feature and happy to report no issues so far. Out of the box! Great job you guys.

Jul 09, 2011
Intown Elite said...
I had issues with Auto Minify and Google Chrome for Mac. Thread here: http://support.cloudflare.com/discussions/site-is-offline/1-strange-behavior-...
Dec 01, 2011
iamlouisbullock said...
Loving this feature, its so much better than minifying the css, html and js in the production stages of my site, especially since its being edited constantly by myself. However, sometimes when I let the cache build, I check my css files, and only one (or two sometimes) are minified out of say 3 css files. Should I just let the cache build longer and not clear the cache for it to minify all of them?
Apr 30, 2012
bikram said...
yes. I have enabled this option in my 2 blogs. It seems that blog is loading faster than before. I love cloudflare.

Leave a comment...