Delegating to Less.js from PHP
It's a couple of weeks since I first wrote about LESS. The good news is that we now have a solution that bridges the gap between PHP and LESS. The even better news is that we have LESS generated CSS in production today, and that it does not impact end user load times or radically alter our development flow.
Shortly after writing about our anticipated use of lessphp, I discovered that its coverage of the language is incomplete; it failed to compile Twitter Bootstrap for example.
less.js is the LESS implementation of choice, so I worked with LESS.app for a few days (a simple Mac app' for compiling LESS files locally that uses less.js under the covers) to get a feel for how LESS would fit into our development process. I found, for instance, that I wanted both .less and .css files checked into SVN (initially at least).
I also had to get up to speed on node.js as a server side container for less.js, a positive experience that I wrote about on my personal blog.
In our development environment:
A custom HTTP LESS server is running on our dev machine on node.js, listening on a specific port
Where we minify and concat our CSS at request time, we now also make requests to the LESS server for CSS files that have a corresponding .less file
The LESS server takes the .less files referenced in each of the local HTTP GET requests and compiles them
The LESS server runs as root and as such is capable of writing to the local file system (something that would be difficult to do as part of the execution of a web request within apache)
The compiled CSS is served, and is persisted in the file system ready to be checked in.
N.B. The CSS file corresponding to the LESS file being compiled should already exist at request time time. This ensures that the node.js process running as root will not create files within developer file systems, it will only modify existing files.
Static CSS (albeit CSS compiled from LESS and checked into SVN) is served as it always has been
Our less server is available as a Slytrunk repository on github.