在运行时将动态变量提供给较少的文件 [英] Serving dynamic variables to a less file at runtime

查看:89
本文介绍了在运行时将动态变量提供给较少的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个大型的ASP.NET MVC应用程序,其中包含大量CSS,约105个不同的文件.这些文件按组件分开,这使它们更易于管理.在运行时,我们使用处理程序来缩小/组合这些内容.

此外,我们的应用程序还利用了皮肤设置;管理员可以为站点自定义字体和颜色.这些皮肤设置是使用NVelocity注入CSS文件的,尽管它很旧,但性能很好.

我想减少CSS的使用,这将允许CSS文件内更多的代码重用和整洁.我正在努力做到这一点的最佳选择.我目前的思路是:

  1. 管理员修改皮肤并保存
  2. 在保存时,应用程序会在光盘上生成一个skin.less文件,这是包含所有变量的主文件少的文件.
  3. 需要较少变量的后续CSS文件在skin.less上执行@import
  4. 较少的文件在处理程序中进行处理和缩小/组合,然后分发给客户端.

我的问题是,这似乎是将动态变量提供给较少文件的最佳方法吗?唯一的选择是在光盘上生成skin.less文件,还是@import语句本身可以引用处理程序,因此无需在光盘上生成文件?

解决方案

我认为您可以这样做.您所谈论的不是完全一样,但是我在此处使用LESS进行蒙皮时做了一些概念验证:

https://github.com/aguyawry/less_tests

我认为一个区别是,在此POC中,商标较少的文件是标记中加载的文件,它导入基本应用样式,然后指定新的var来覆盖基本中的初始值.

此POC完全是客户端,但实际上,我们也在服务器端.实际上,我们正朝着建立一个UI以便客户自己选择样式(bg颜色,边框颜色....),然后将其呈现出皮肤样式表到系统中.

我认为TheZ的评论不适用,因为您正在服务器端进行所有操作.只有在执行此客户端操作时,才会发生阻塞.

We have a large ASP.NET MVC application with a large amount of CSS, ~105 distinct files. These files are separated by component, which makes them easier to manage. At runtime, we minify/combine these using a handler.

Additionally, our application utilizes skin settings; the administrator can customize fonts and colors for the site. Those skin settings are injected into CSS files using NVelocity, which although it's old is quite performant.

I'd like to move the CSS to using less, which will allow for more code reuse and cleanliness inside the CSS files. I'm struggling over the best option to do this. My current train of thought is this:

  1. Administrator makes skin modifications, and saves
  2. On save the application generates a skin.less file on disc, which is the master less file containing all the variables
  3. Subsequent CSS files that require less variables do an @import on the skin.less
  4. less files are processed and minified/combined in a handler, and served down to the client.

My question is, does this seem like the best approach to serving dynamic variables into the less files? Is generating the skin.less file on disc my only option, or can the @import statement reference a handler itself, so there's no need to generate a file on disc?

解决方案

I think you can possibly do it this way. Not quite the same thing you are talking about, but I did a bit of a proof of concept for using LESS with skinning here:

https://github.com/aguyawry/less_tests

I think one difference is that in this POC, the branded less file is the one loaded in the markup and it imports the base app styles, then specifies new vars that override the initial values in the base.

This POC is all client side, but in practice we do this server side as well. We are actually moving toward building a UI for clients to choose their styles themselves (bg color, border color....) and then will render out a skin style sheet from that into the system.

I don't think the comment by TheZ applies since you are doing everything server side. Blocking would only happen if you were doing this client side.

这篇关于在运行时将动态变量提供给较少的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆