metabrainz/geordi — pull request #24 by mwiencek (2014-07-31 21:15:05+00:00)
Title: Requirejs

Adds requirejs and moves all scripts to the bottom (except less.js, otherwise there'd be a visible delay before styles are applied on dev servers), which was pretty easy 'cause there's not much JS at the moment.

I added a `build_resources.py` script to build things. Called without arguments, it optimizes/compiles js/css, or you can pass it a list of actions like `build_resources.py scripts styles`.

The build script outputs combined/minified js to `geordi/geordi/static/build/scripts/` and compiled less files to `geordi/geordi/static/build/styles/`. So everything outputted by the script goes into that build directory, which is also ignored by .gitignore.

Originally I was using Gulp, which I loved for the most part, but I ran into some very annoying issues where it wouldn't output paths correctly, probably 'cause r.js doesn't integrate well with the whole streams thing. And anyway, the python script here is shorter in length than the gulpfile I had and requires less dependencies.

This doesn't include any sort of cache busting, e.g. it doesn't add hashes to the compiled file names. Which I guess there's two decent ways to do: it could add hashes, and then output a "paths" config that gets passed to requirejs (something like `{"paths": {"common": "common-101a6ec9f938885df0a44f20458d2eb4"}}`). Or we could not do anything and use something like https://github.com/pagespeed/ngx_pagespeed on production servers.