I discovered LESS after adopting Bootstrap for my personal website. LESS extends traditional CSS syntax, adding dynamic behavior via variables, mixins (reusable chunks), and nested rules among others. Less.js is probably the best known implementation of LESS, however there are LESS compilers for various other languages, including lessphp. This means that LESS can be incorporated within existing architectures without the need to adopt Node.js. Also, all existing CSS files are also valid LESS files so it is possible to incrementally add LESS markup to a code base after enabling LESS, (note that LESS will transform pure CSS too though).
Adding dynamic behavior to CSS is an attractive proposition, but the adoption of LESS requires some careful thought. The concerns that emerged during our conversations in the office boiled down to:
The introduction of a compilation step since LESS needs to be interpreted and transformed into regular static CSS.
Future proofing for a world where LESS is possibly no longer supported.
The introduction of a disconnect between the code being written in LESS and the corresponding CSS being interpreted by the browser.
The compilation is the biggest concern, so here is a look at our options.
Introducing a Compilation Step
It turns out LESS compilation is slow. After exercising LESS with some real files (mostly static CSS, with little flourished of LESS), it became evident that the time taken to compile LESS is nontrivial; taking around 1 second to compile the CSS needed for the top page of Wonderwall for example.
It is well documented that client side compilation via Node.js is not practical, but it is worth reemphasizing that client side interpretation is out of the question. The end user cannot suffer as a result of increased page weight or rendering time, especially not solely to diversify our code base! With this in mind, we have three options:
The first time a LESS/CSS file is requested from the browser, we compile it, serve it, and cache it. We would do this both in development and production. It'd make the initial request slower, but not that much slower, and it would happen infrequently. The LESS and compiled CSS versions would be essentially the same file; only the LESS file would be under version control. The CSS version would be transient, only living in the cache.
In development we do on demand compilation as in #1, but in production we make the LESS compilation part of our deployment/build script. So our production servers would have the compiled CSS and not incur the performance hit of #1. Again, only the LESS version of the files would be under version control. The CSS version would exist in cache in development and on the filesystem/cache in production.
Compiled CSS in production like #2, but with some kind of gross manual compilation step in development. We would have both CSS and LESS files under version control and have an added disconnect of editing a different file from the one we're including in our templates.
Right now, we're weighing up #1 and #2, leaning towards #1 for simplicity. We need to get some metrics around the frequency of cache population before we roll it out though.