Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LESS compilation on Play 2 is seriously slow

LESS compilation in my fresh Play 2 install is genuinely slow. Even after placing an '_' on files that do not need direct compilation, a page refresh after a LESS edit takes ~8 seconds to complete. This is compared to a local compile using Codekit which takes less than a second.

Any suggestions on speeding up this process? Is it worth filing a bug against Play to have this looked at?

Here are details on my file sizes: My LESS setup is very simple. _reset.less (.5k) _desktop.less (13k), _tablet.less (10k), _mobile.less (8k), _sprites.less (25k) files. An all.less (.3k) file that puts it all together. That's it. The resulting css file is 53k.

like image 630
Christian Avatar asked Dec 03 '12 20:12

Christian


3 Answers

I did a write-up of a small investigation into this problem. You can find it here.

Bottom line: I get faster performance by switching to Sass. It's not hard to do. Use the Play-Sass SBT plugin and, if you're using Bootstrap, use the SASS Bootstrap files from the sass-twitter-bootstrap project.

Precompiling your LESS files via the lessc command is another solution, and it's quite fast.

Assuming your project uses Bootstrap, using a precompiled Bootstrap, rather than the Bootstrap LESS files, is also a big win, because the Play LESS compiler recompiles all LESS files when one of them changes, and Bootstrap is rather large. But, for some of us, using a precompiled Bootstrap is inconvenient...

Using Play 2.0's Rhino-based, on-demand LESS compilation is the slowest option. Pig-slow, in fact. And ignore my comment about incrementalAssetsCompilation. It's documented, but it does not appear to be in the 2.0.x code base.

EDIT (22 May, 2013) Jonathan Parsons has put together a play-lessc plugin that uses the lessc command to compile LESS files. It can dramatically decrease LESS compilation times in a Play project. See https://github.com/jmparsons/play-lessc

like image 176
Brian Clapper Avatar answered Jan 04 '23 01:01

Brian Clapper


This will dramatically reduce the compilation time:

export SBT_OPTS="$SBT_OPTS -Dsbt.jse.engineType=Node"

It makes Play use Node instead of Rhino when running JavaScript.

like image 31
Oscar Broman Avatar answered Jan 03 '23 23:01

Oscar Broman


From Play Framework 2.3, you can use node.js as default JavaScript engine, which is used for less compilation, js lint, CoffeeScript etc..

Download and install node.js (https://nodejs.org) library and put

JsEngineKeys.engineType := JsEngineKeys.EngineType.Node

to build.sbt.

Reference #1 - Reference #2

like image 25
Lukas Jelinek Avatar answered Jan 04 '23 01:01

Lukas Jelinek