Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile less on front-end

Tags:

css

less

How can i compile less in efficiently on the browser? I'm using this code to compile less on the browser but this is taking very long time in compilation. I need to compile it on the browser not in back-end.

<script>
    less = {
        env: "development",
        logLevel: 2,
        async: false,
        fileAsync: false,
        poll: 1000,
        functions: {},
        dumpLineNumbers: "comments",
        relativeUrls: false
    };
</script>
<script src="http://cdn.storehippo.com/assets/less-1.5.0.js"></script>
<script src="lessfile.less"></script>
like image 658
Rohit Avatar asked Jan 09 '15 06:01

Rohit


People also ask

How do I compile LESS files?

Pre-compiling LESS into CSS: To compile LESS into CSS, we use the below command in a command prompt. The lessc command lets us precompile our LESS file into a basic CSS file. This helps us in writing modular code using LESS programming and still getting all the benefits of CSS by compiling it into traditional fast CSS.

What is LESS in web development?

Less (which stands for Leaner Style Sheets) is a backwards-compatible language extension for CSS. This is the official documentation for Less, the language and Less.js, the JavaScript tool that converts your Less styles to CSS styles. Because Less looks just like CSS, learning it is a breeze.

How do you add LESS to HTML?

Create a stylesheet with . less extension and link it in your document using the rel="stylesheet/less" attribute. You are all set and can compose styles within the . less .

How do I compile LESS to CSS in Visual Studio?

css file nested under it in Solution Explorer after being enabled on the project. By default, compilation is off and that's indicated by a watermark at the bottom right corner of any LESS file. To enable LESS compilation, simply click the watermark and it changes to indicate LESS compilation is "on". All .


1 Answers

In fact your question is very broad. Why do you have to compile your code client side? How does you code look? What, if any, changes when you compile you code again?

See also:

  1. how to optimize Less CSS? how to generate 1 minified version of all less files? I am also using modifyVars
  2. Is it faster to precompile less?

In most cases you should not use Less in a product environment. When you do for some reason you can try to optimize compile time.

You are using env: "development", that option prevent Less from caching the compiled code. Every @import directive in your code requires an file that has to be open and read over http. Consider to split your code into a static part (compile css) and dynamic part that have to be compiled for every request.

update

Also see: https://github.com/less/less.js/issues/2339 if your are using Safari:

You can re-enable chunking with {chunkInput: true} in the less options (or data-chunk-input="true" attribute on the less link).

like image 162
Bass Jobsen Avatar answered Sep 21 '22 12:09

Bass Jobsen