简体   繁体   English

运行LESS服务器端与客户端

[英]Running LESS server-side vs. client-side

What are the advantages / disadvantages to running the LESS framework client-side vs. server-side? 运行LESS框架客户端与服务器端的优点/缺点是什么? Does page load time take a hit if you run it client-side? 如果您在客户端运行页面加载时间会受到影响吗?

On the server, you have to take more care with your cache control headers and you sacrifice a bit of CPU power. 在服务器上,您必须更加小心缓存控制标头,并牺牲一点CPU功率。

On the client, it breaks if JS isn't available. 在客户端,如果JS不可用,它会中断。

(For your production systems,) do it at build time and just serve up static CSS. (对于您的生产系统,)在构建时执行它,并且只提供静态CSS。 That's efficient and reliable. 这是有效和可靠的。

Using ASP.NET MVC 4.0 Bundling you can use: 使用ASP.NET MVC 4.0 Bundling,您可以使用:

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 ... 缓存,转换(服务器端),捆绑和...

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) 在CPU性能方面较慢(可能会影响移动设备)
  • Breaks without JS 没有JS的休息

Server-side: 服务器端:

Advantages: 好处:

  • Faster 快点
  • Client JS independent 客户端JS独立

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. 在开发中,编译较少的客户端可能非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM