The best option I've seen so far is WebAssets.
From the documentation:
webassets is a general, dependency-independent library for managing
the assets of your web application. It can merge and compress your CSS
and JavaScript files, supporting a wide variety of different filters,
and supports working with compilers like CoffeeScript or Sass.
You can use it in standalone mode with tornado (see the specific documentation).
Set up is easy and pretty straightforward:
from webassets import Environment
static_directory = "../static"
output_directory = "/static"
my_env = Environment(static_directory, output_directory)
Of course you can customise it far better. The rest is pretty well explained in the documentation.
Main features:
- Easy integration
- Possible to compress static files in advance (command-line tool)
- Possible to compress static files on the fly
- Supports most minifying/compression libraries (JS, CSS)
- Supports LESS/SASS compiling inside the browser
- Supports compression of JS Templates inside the browser (Handlebars...)
- Supports CSS sprite mapper
Example of what a template (here, Jinja2) looks like after proper configuration:
# css
{% assets filters="cssmin", output="css/compiled-layout.css",
"css/custom.css",
"css/bootstrap-datepicker.css",
"css/typeahead.css" %}
<link rel="stylesheet" type="text/css" href="{{ ASSET_URL }}">
{% endassets %}
# js
{% assets filters="jsmin", output="js/lib/compiled-libs.js",
"js/lib/jquery-2.1.1.min.js",
"js/lib/jquery-ui.min.js",
"js/lib/bootstrap.min.js",
"js/lib/bootstrap-datepicker.js",
"js/lib/d3.min.js",
"js/lib/typeahead.bundle.min.js",
"js/lib/moment.min.js",
"js/lib/handlebars-v2.0.0.js",
"js/global.js" %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
I've been using WebAssets tied to Flask for a year with no hassle and it's perfectly reliable, plus well-maintained: it's been there for several years, and last commit to date was yesterday.