LESS is more

Normally we are intended to use “less” in conjunction with “free time”, just as “less free time for hobbies” or even “earning less money”, but in this case “LESS” means a great way to make content style sheets (css) dynamic.

When writing styles sheets we normally need to repeat and repeat and repeat the same stuff, reuse colors or calculate a lot values depending on others. Using LESS this is done dynamically. And the best: Its syntax follows valid css, so you don’t need to change any line of your code to port.

The official LESS framework is available as client-side JavaScript project. But on github I found a nice PHP implementation, called less.php, which can be used either from the command line or directly on the server. But why do I prefer a not-yet ready PHP implementation over the official and even quite nice JavaScript one?

When working on so-called static websites JavaScript is not well seen and using it in major places would hide all users, that don’t activate JavaScript for default.

Another point is about minimizing web requests. Style sheets created with LESS won’t need to open up new connections – except for images and external fonts – , cause all imported style sheets will automatically be attached on the server side and reduce the page load.

Thanks to its simple structure usage is really easy (showing just the basics):

$less = new LESS(); // initialising
$less->setBasePath(); // (optionally) setting a base path for absolute imports
$less->setRestrictPath(); // (optionally) setting a path, which restricts import paths to outside
$less->parse($content); // parse $content
$less->parseFile($file); // parse the content of $file
echo $less->output();