Asset Management Unbroken

Zohar Arad. © 2014

About Me

Let's talk about assets

Easy Right?
Wrong! Asset management is pretty broken...

Now What?
Let's see what's broken and how to fix it

Scenario #1 - The Freelance FED

I only do the front-end. I'll use some automation for pre-processing and possibly building and optimising. Once finished, I hand off the project to the client.

But... what about deployment, cache-busting, GZipping, CND?

Scenario #2 - The Over-Optimiser

For the sake of development speed and separation of concerns, the backend is only an API server. It doesn't do any FEDdy stuff. That's the FED's job (or the browser's).

So... even though your backend supports templating, pre-processing and dependency management, the FED should just write their own asset-management code?

Scenario #3 - The RequireJS Addict

RequireJS is awesome! Awesome I tell you. It lets me defined dependencies, packages and helps me ensure my code is self-contained! It even has a build system with a very catchy name.

Right. But you still have to manually pre-process, cache-bust and GZip your build.

Scenario #4 - The DIY Know-it-all

Our project has very specific requirements that aren't fully addressed by community tools, so I wrote a complete asset manager in Clojure since it's the fastest language on earth. Only I know how it works, but rest assured it works flawlessly (and very quickly, in parallel threads, on our CI server).

Right. So you wasted all that time on a proprietary solution to a problem everyone shares.

Scenario #5 - The Careless FED

I still haven't gotten around to convincing my boss we should add some asset-management capabilities to our code, so meanwhile I just include my CSS and JS as they are and we serve them from Apache.

Ok.
Enough Llamas

Unbreaking Asset Management

Automatic Solution - Use existing tools
Ruby Sprokets, Jammit
Node.js connect-assets, connect-mincer
PHP Sprockets-PHP, Bonfire Assets (no cache busting)
Python webassets

Unbreaking Asset Management

Manual Solution - Gulp example
Pre-processors gulp-sass, gulp-less, gulp-coffee
Templates gulp-jaded, gulp-handlebars, gulp-assetpaths
Optimisation gulp-minify-css, gulp-uglify, gulp-concat,
gulp-tar, gulp-gzip
Cache-busting gulp-rev, gulp-rev-collector, gulp-rev-all
CDN gulp-awspublish, gulp-cloudfront, deploy-azure-cdn

What about deployment?

Deployment

Our deployment system needs to painlessly support:

Deploying Assets

Deployment Tools

Ruby Capistrano, Mina
Python Fabric
Node Deploy, Flightplan
Bash Roll your own, Git (Just Kidding)
PHP Long rope and a noose

Git Deployment
Sucks

Putting it all together

You should always prefer to use existing tools. Moreover, you should always prefer to combine backend framework support (like connect-assets/mincer) with a solid deployment tool (like Fabric).

But... in case you can't here's a detox plan.

Detox Plan

  1. Choose a solid, suitable deployment tool

Detox Plan

  1. Make sure build tasks are runnable from CLI

Pipeline Flow

Pre-compile / Pre-process → Concatenate & Minify → Save →
MD5 file content → Add MD5 value to file-name →
Create Cache Manifest → Update templates with new file-names →
GZip → Upload to CDN

Pipeline Flow

If you're a real hero, run MD5 to CDN steps on images too (use MD5 of Base64 value for content diffing)

Closing Thoughts

Thank You!

QRCode

Scan Me...