Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS on Server Side?

I ran into LESS website and this is the description of they are doing"

LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions. LESS runs on both the client-side (IE 6+, Webkit, Firefox) and server-side, with Node.js.

What does it mean "and server-side" with Node.js? I know that you can write server-side code with javascript using Node.js, but what is the meaning of having CSS on server-side and how is it useful?

like image 317
K'' Avatar asked Nov 18 '11 14:11

K''


4 Answers

What does it mean "and server-side" with Node.js? I know that you can write server-side code with javascript using Node.js, but what is the meaning of having CSS on server-side and how is it useful?

It's not the CSS that's (optionally) done server-side, it's the LESS processing, which results in normal CSS that gets sent to the client.

So if you have a .less file on your web server with this:

@color: #4D926F;

#header {
  color: @color;
}
h2 {
  color: @color;
}

...and you have your web server configured to process .less files through the LESS compiler running under Node.js (e.g., just as .php files are processed through the PHP interpreter, .py files through the Python interpreter, etc.), then the output of the LESS compiler (pure CSS) gets generated and sent to the client:

#header {
  color: #4D926F;
}
h2 {
  color: #4D926F;
}

This is (a tiny bit) more load on your server, but means you don't have to worry about running the LESS compiler on the browser (e.g., you can support non-JavaScript clients).

like image 127
T.J. Crowder Avatar answered Oct 02 '22 15:10

T.J. Crowder


I'm pretty sure it means that you can run the LESS code with Node.js during your application build phase in order to pre-expand the CSS.

In other words, it lets you do that server-side before deployment (or, I guess, on demand, if you wanted to) in order to improve client-side performance.

like image 24
Pointy Avatar answered Oct 02 '22 15:10

Pointy


The LESS compiler is implemented in JavaScript and the compiler can run both on the client as well as the server (using NodeJS)

like image 45
pradeek Avatar answered Oct 02 '22 16:10

pradeek


my bet: it would compile the css server-side, and push it to the client

like image 28
elias Avatar answered Oct 02 '22 14:10

elias