Less.js will obsolete CSS
fadeyev.net
fadeyev.net
"Less.js is a JavaScript implementation of LESS that’s run by your web browser. As any JavaScript, you include a link to the script in your HTML, and…that’s that. LESS is now going to process LESS code so instead of including a link to a CSS file, you’ll include a link directly to your LESS code. That’s right, no CSS pre-processing, LESS will handle it live."
No mention that that would be ineffective for a production site. In fact, he claims that live processing won't have noticeable lag, which is just false.
First back it up with numbers, then we talk.
Maybe.
Remember, we have to design our sites as if the user is poised over the back button.
A trivial CSS file (foo {a: b}) takes about 0.11s. This is probably mostly time spent spawning Node and loading the JS.
The combined CSS for GitHub, about 160K, takes about 1.6s. This is already longer than most HTTP requests.
The doubled CSS for GitHub (the same CSS twice in a row), about 316K, takes about 4s. This is quite large, although there are few sites that have this much CSS.
I tried to run it against the minified CSS for caring.com, but after 2m it hadn't terminated so I gave up. It's likely that this is due to a bug in the implementation rather than slowness.
By airing the file out a bit (just adding some double line-breaks), and passing -O2, it goes down to 177ms :)
For what it's worth, -O2 brings the compile time for github.css down to about 1.5s.
http://github.com/cloudhead/less.js/blob/master/benchmark/be...
Which has all the features of LESS in it, and weighs 94KB (3600loc), compiles in 130ms on my macbook pro.
I would say that's plenty fast. You can try it out by running `$ make benchmark`
It's also worth mentioning that plenty of people who care about page load times would still care about 130ms. It's not as glaringly awful as 1.5s, but it's definitely comparable to the sorts of times under discussion. See http://developer.yahoo.com/performance/rules.html and http://code.google.com/speed/page-speed/docs/rules_intro.htm...
Well, it's way too late for that. You need to send that statement back to mid-1990s.
Or does your processor natively execute Javascript text?
That dogmatic declaration is nonsense. Compilers are just code. Certain programming language compilers are very slow due to the immense complexity of their task but there's nothing intrinsically slow about compilers/interpreters next to any number of other normal tasks. I've even sped code up by replacing large swathes of ad-hoc hard-coded crap code with a nice small interpreter that was small enough to be feasibly optimized, rather than the mass of code that was previously there that everybody was afraid to touch.
The really slow part would be the parsing, really, and if Less.js doesn't already have a "straight from JSON" mode, it would be easy enough to add one, then you could actually use the "native" Javascript parser and compiler.
However, that's not the case right now. Maybe in the future Javascript's string parsing will become dramatically faster, but in my benchmarks elsewhere on this thread, it's clear that for large files less.js is pretty slow relative to HTTP.
As for serving it up as JSON: no one wants to write stylesheets in JSON. The reason Less became popular as an alternative to Sass was that it had a CSS-like syntax.
You don't have to. You can use a compiler to generate JSON to feed to the system, retaining the flexibility of having the compiler running but skipping the parsing step. Why not compile straight to CSS? Well, why not? For simple sites that may be just fine. For more complicated sites it might be desirable to screw with the CSS before compiling.
My real meta-point here is that compiling isn't that scary. The idea of load you may get from g++ or GHC is not generally applicable. And as JS gets closer and closer to C-speeds it'll matter even less. (Not saying it will reach them, but you don't have to.) And there are already quite a few compilers in the mix; every web language has one (JS, CSS, HTML, SVG) and adding another is not like an enormous scary step. I suppose this is another consequence of the continuing deplorable move away from having compilers be a required class for a degree; truly it is one of the most powerful techniques of computer science that is relatively difficult to fully encounter outside of a formal education. (Like everything else in programming, it isn't impossible, but as it is very easy to walk away with a degree without ever having encountered one, so much moreso it is easy to not encounter one in informal education too.)
However, I would submit that string bashing also ought to be amenable to JIT optimization. What will kill you in the browsers is interacting with the DOM/browser itself, and that's not going to go away as that code is increasingly already as optimized as it's going to get. However, CSS already has that problem, so if you can dynamically snap some CSS together on the client side and then feed it to the usual CSS processes, it doesn't have to be a large loss.
I also expect the browers to continue to work towards support more of this stuff being done dynamically; if you can better hook into the page generation process, you can help the browser avoid extra stupid work, like starting to layout the page with the entirely wrong CSS. We're still a ways from this entire process being optimized; I feel we've finally left the stupid ages in the browser world, but we're still working.
I'm certainly not afraid of compilers. I write Sass, so I'm pretty intimately familiar with what's going on. My point was not that compilers are inherently scary and/or slow (although I stand by my original point that if it's compiling to CSS it will always be at least somewhat slower). I was just making the claim that the current speed of less.js is too slow for practical production use.
Even better: Or does your processor natively execute HTML text?
In addition, with more mobile internet providers capping monthly usage, every byte counts.
I'm assuming that these CSS compilers generate larger output CSS files than their input.
In fact this is exactly what we do with Objective-J, and if Less.js doesn't already then I expect they will soon.
The Sass compiler was (is?) more mature, and the language feels more consistent (see the '&' operator in Sass vs the :hover special case in Less). The editor/tool support was quite a bit better too.
Sass doesn't have a javascript in-browser implementation (afaik), but for rapid development it can watch a folder/file for changes and automatically recompile to static CSS files.
Plus there's a firebug plugin, so you get Sass line numbers / references instead of compiled CSS line numbers: https://addons.mozilla.org/en-US/firefox/addon/103988/
See the examples on their front page: http://sass-lang.com
They have a command line tool "sass-convert", which can convert between the syntaxes (and from Less)
That said, I agree that SASS is more mature. I've used each on at least two projects now, and, with the release of SASS 3.0's and SCSS, I'm committing to SASS. This client-side parsing is a cool trick, but it's easy to do my CSS generation at the same time as my javascript minification. I just don't need it.
I welcome sensationalist link-bait headlines if they have weight behind them. Don't blame the sizzle, blame the steak.
With Less, SASS and similar tools becoming more popular recently, I wouldn't be surprised to see Chrome or Firefox experimentally include their own implementations.
LESS is beautiful as it is. But processing LESS code in the browser would mean that I can't use LESS.js for mobile web apps. Although there are mobile devices with 1ghz processors already out in the market, there is still a lag in rendering mediocre-weight pages that contain js on mobile devices.
P.S: Congrats on keeping LESS simpler.
I don't know. It's not bad, but it's not for me. But going as fas as to say it will obsolete CSS, that's just too much.
Nothing, in production you'd use the compiled ver. The article should make this clearer though.
Having said that, I have the same problem with LESS.js that I have with various other JavaScript layout techniques - I simply don't like relying on JavaScript to control the look and feel of a web page. I think it's awkward, inefficient, and just asking for trouble. Mostly, I also think it's completely unnecessary.
So I still don't think something like LESS or SASS is the answer. My point was CSS is, despite its poor design, fundamentally easy to understand in terms of how it's supposed to work. No, it doesn't always work like it's supposed to and sometimes you have to work around that, but at its core, the syntax, the structure, and methodology behind it are dead simple. Building something like LESS/SASS to run on top of/underneath CSS to then generate said CSS markup seems redundant, when instead what needs to happen is that the focus needs to be on fixing the flaws of CSS, not adding another layer of abstraction.
And how does LESS/SASS handle all of those hacks? You still have to do them. You just write them a bit differently. So really, besides variables, what added value does it provide?
Variables alone make LESS/SASS worthwhile, but even putting those aside, let me give you an example of added value: importing other files. With LESS/SASS you can import different files, and they get compiled into one CSS file. With CSS if you use @import, you've got an additional HTTP request, which negatively impacts performance. LESS/SASS gives you additional flexibility in organizing your CSS. In LESS/SASS you can just go to the individual file that deals with typography, as opposed to the tricks designers have used to find things in a large CSS file (e.g. putting a table of contents at the top of the CSS in comments, with a unique string for each section, which you then use Ctrl-F to look for to find the section of rules you're interested in.)
I'd recommend trying it out on a small project if you haven't already, to see for yourself.
Also see:
MongoDB - save data in BSON (binary JSON) And query with JSON
Node.js - Build an entire smoking fast server side web app with JavaScript objects. Bonus: run a node app on Heroku to compile and varnish cash less.js if you are worried about performance
Mustache.js or Pure - JavaScript templating to turn JSON into HTML
V8, tracemonkey, Nitro - blazing fast JS interpreters everywhere that will .eval JSON
Convergence anyone?
for (var $i = 0; $i < count($nav_links); $i++) {
echo '<li><a href="' . $nav_links[$i] . '"></a></li>';
}
I can see it now, a day without HTML!</sarcasm>
That way, you'd also have the benefit of defining often-used attribute values (e.g. colors) in a variable, and you could also group often-used combinations of attributes together in a variable or sub template.
I'm seriously considering writing a Python-based "Preprocessor" language which lets me drop in Python code on any file, and deals with transforming it into the final "compiled" file.
You are probably interested in Pyratemp – a simple, well-designed and well-documented template engine that allows arbitrary Python expressions:
http://www.simple-is-better.org/template/pyratemp.html
BTW, I personally use the XSLT template language. It is language independent, but still extendable with user-defined functions written in the programming language of your application. Note that despite its name, XSLT does not only provide for XML output, but handles text output and HTML as well. In Python, you can find a excellent XSLT processor in the 4suite package:
http://4suite.org/docs/CoreManual.xml#xslt_engine
However, the syntax of XSLT is a bit clumsy, so I'll probably switch to XQuery in the future.
Template Toolkit is such a beast: http://template-toolkit.org/
Beyond its normal Perl (and Python) web templating usage I've also used (and abused) TT for:
* All my static websites
* CSS (dynamic and static)
* Pre-process scripts (including Javascript)
* Multi-lingual email
* Creating (end user) configurable data exports (eg. CSV).
* Websurvey language!
* And probably other things I've (hopefully!) forgotten :)
NB. See "ttree" & "tpage" in docs for standalone usage.
Link for anyone interested: http://en.wikipedia.org/wiki/M4_(computer_language).
By the way, I really think that to work (i.e. become usable, maybe even popular), this needs to be built on an existing and popular language. Otherwise it's too steep a learning curve.
Ideally, I'd like to be able to put in code in the text file wherever I want, be able to put the value of expressions in the code, and that's it.
It is the base of GNU Autoconf, so everyone who touched a configure.in / configure.ac file did in fact work on M4 code.
(... which is then expanded to a portable shell script also known as the ./configure script.)
http://nedbatchelder.com/code/cog/
I used it several years ago with great success.
The box model is fine when you just need to "flow" things around things, like text around images, and typical blog designs, but when you develop complicated interfaces it really shows its limitations and costs many hours of frustrating effort.
box-sizing: border-box
with -ms- (IE8), -moz- and -webkit- prefixes.The CSS3 UI module is a candidate recommendation. Setting:
box-sizing: border-box;
essentially puts the CSS box model render mode to where it was in IE5 (which is, frankly, the only sensible way to do it). Right now, it is available with Mozilla, Webkit and Microsoft prefixes (as are most of the UI module properties).
CSS has very weak layout capabilities.
CSS has weak typography.
CSS has weak colour system support.
In each case, this is partly due to limitations in the underlying model, but also partly due to having limited syntax.
In each case CSS3 modules may improve things somewhat if and when they are widely supported, but even the best proposals there aren't even close to the power of a good DTP tool or the control of a native application. When the web is trying to take over from both, CSS isn't a good tool, it's just the best we've got right now.
display: inline-block;
width: ...
?Besides if you don't care about antiquated browsers (eg IE6), the inline-block is a viable option. In IE it will require some massaging, but it can be made to work quite easily.
(1) It's useless. Just pre-process the style sheets statically. No need for PHP, Ruby or any server side dynamic scripting whatsoever. It's simpler, and yields less requirements for everyone.
(2) It exclude users. Not only the paranoid ones that run noscript and adBlock, but also the ones that just don't have Javascript like Dillo users. (Dillo is interesting for old, weak computers.) That's still a tiny minority, but they do exist.
Something useless that exclude users clearly isn't the best tool for the job. Unless punishing noscript users is a feature… Now, of course javascript is more capable than (pre-processed) CSS alone. But the article didn't seem to use those capabilities.
I'll definitely be keeping an eye on this.
I've worked as a UI developer for 12 years now and I wouldn't go near something like this because there is no value. At least the server side version you can pre-process and package up for live after your developers have saved literally minutes by using it. You need to know CSS inside out, so you have to then unlearn and relearn different parts just to do something you can already do with find + replace.
And worse, you are even including and downloading files that the browser cannot even interpret itself without relying on another download of JavaScript as well, so you're giving something that works 100% of the time (assuming someone has CSS on) another point of failure. Most of my time in UI has been in public sector education trying to push standards and quality from various suppliers to the Govt and seeing things like this from said suppliers (I've seen worse to be fair, but I've seen something like this before) is always an unpleasant experience.
Lots of developers will tell you that it's fine to use systems like the 960 Grid System for rapid prototyping, but you shouldn't use them for final, "production" sites. Their argument is that "littering" your code with classes like "grid_4", etc. is not semantic (and they're right).
So here's what I would love to do: use a system like 960 in development, but instead of using names like "grid_4", use actual, semantic names. But behind the scenes, I'll use less to "inherit" the grid_4 properties into the semantic name.
E.g., assuming I have: "<div class="grid_4 article_header>", I'll remove grid_4, but use less to make "article_header" inherit grid_4's properties. That way my html remains semantic, but I get the full power of systems like 960.gs.
.class-name .clearfix font-size: 1.2em
There are other ways to do it like one long string of selectors followed by the clearfix code, but they're not as convenient or readable.
For one example, you can define "constants". That means you can define a color once with a name (say, LINK_COLOR = #aaa), then use that name over and over. Then, if you ever feel like changing that color, you only have to change it once (where it says LINK_COLOR = ), not every time.
Other benefits are something akin to "functions", and ways of "nesting" your CSS which automatically makes certain classes only apply to nested elements (this is something most people do anyway, they just do it by hand).
For example, if you want to make an inline list it's as easy as:
li +inline-list
Basically, it's not really about reducing syntax or size of the file (which does get smaller for large stylesheets), it's all about making the stylesheet easier to build and maintain.
I was never forced to define important colors more than twice in my CSS style sheets, usually defining them just once. Maybe my document structures are too simple to get into trouble - but maybe that's the whole trick.
(i.e. producing less bloat rather than making bloat more manageable.)
This is especially true for web sites which should at least look as simple as possible. So in principle, there should be always a way to produce HTML whose DOM structure isn't too complicated, no matter what the content is.
Def initely
It's an opinion, take it with a grain of salt.
(BTW, I dislike MW because it takes all nuance out of the language and dumbs it down to an inexpressive mess.)
Obsolete is a verb, but it is a poor choice. A better
choice would be obsolesce, as in: "LESS.js will
obsolesce CSS"
"Obsolete" is the correct word because it's a transitive verb (eg, [subject] obsoletes [object]), while obsolesce is an intransitive verb (eg, [subject] obsolesces).If you take a gander at WordNet or even OneLook (searches multiple dictionaries), you'll find that the majority list obsolete only as an adjective, including Webster's 1828.
However, I concur that obsolesce would have been a better choice.
Sounds strange to the modern ear though.
(BTW, I used to be a grammar nazi years ago.)