Running LESS server-side vs. client-side

2019-04-04 18:28发布

What are the advantages / disadvantages to running the LESS framework client-side vs. server-side? Does page load time take a hit if you run it client-side?

3条回答
\"骚年 ilove
2楼-- · 2019-04-04 18:56

On the server, you have to take more care with your cache control headers and you sacrifice a bit of CPU power.

On the client, it breaks if JS isn't available.

(For your production systems,) do it at build time and just serve up static CSS. That's efficient and reliable.

查看更多
Ridiculous、
3楼-- · 2019-04-04 19:08

Client-side:

Advantages:

  • Better debugging
  • May be easier in development

Disadvantages:

  • Slower in terms of bandwidth
  • Slower in terms of cpu performance (may affect mobile devices)
  • Breaks without JS

Server-side:

Advantages:

  • Faster
  • Client JS independent

Disadvantages:

  • A little bit more work to implement

My advise:

Never ever use client side in production. In development it may however be very useful to compile less client side.

查看更多
叼着烟拽天下
4楼-- · 2019-04-04 19:09

Using ASP.NET MVC 4.0 Bundling you can use:

var bundle = new StyleBundle("~/Content/style").Include(
    "~/Content/myStyles.less");
bundle.Transforms.Add(new LessTransform());

bundles.Add(bundle);   

Everything will be handled very nicely. Caching, Transforming (server-side), bundling and ...

查看更多
登录 后发表回答