LESS compilation on Play 2 is seriously slow
Asked Answered
B

3

10

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.

Bedeck answered 3/12, 2012 at 20:15 Comment(4)
how many less files do you have? How big each?Stroke
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.Bedeck
I think there might be a way to tell Play to use the native less app instead of the interpreted one via Rhino. But I can't find any docs on that. :(Nun
I've noticed this problem, too. It's bad enough that I'm considering switching to the play-sass plugin, which uses the Sass Ruby gem and the sass command. Either that, or I'm considering writing my own plugin that uses lessc (assuming I can't figure out how to do that via whatever configuration parameter James Ward mentioned... time to crawl the source, I suppose). In any case, there's an experimental setting that may help you. See the bottom of playframework.org/documentation/2.0.1/Assets, where it talks about the incrementalAssetsCompilation setting.Vaulted
V
8

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

Vaulted answered 12/12, 2012 at 22:38 Comment(0)
V
2

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.

Viniculture answered 23/3, 2015 at 12:10 Comment(0)
S
2

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

Subterrane answered 26/3, 2015 at 18:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.