生成动态CSS [英] Generating dynamic CSS

查看:84
本文介绍了生成动态CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

处理用户自定义样式的最佳方法是什么?作为我要查找的结果的一个例子,这就足够了:

What is the best way to handle style that that is user-customized? Just as an example of the result I'm looking for, this would suffice:

body {
   color: {{ user.profile.text_color }};
}

但是,提供CSS作为视图似乎会导致大量

However, serving CSS as a view seems like it would cause a significant amount of overhead in a file that is constantly requested, so this is probably not a good solution.

用户没有访问CSS文件的权限,我们必须假设他们有没有web开发知识。

The user does not have access to the CSS files and we must assume that they have no web development knowledge.

推荐答案


但是,提供CSS作为一个视图似乎会导致

However, serving CSS as a view seems like it would cause a significant amount of overhead in a file that is constantly requested, so this is probably not a good solution.

如果您要生成的文件中包含大量的开销,那么这可能不是一个好的解决方案。 CSS

And what if you would generate that CSS once?


  1. 默认CSS是: /common/css.css

  2. 会员自定义CSS,现在< link /> 元素指向 / user- specific / 123。 css?ts = 123123123 123 当然是成员的标识符, ts 参数包含时间戳 - 上次CSS修改的日期

  3. 确保您的CSS生成器设置了适当的HTTP标头,负责客户端缓存

  4. 用户浏览器请求CSS文件 - 服务器回复简单 304未修改标题 - 无需任何脚本执行或内容下载

  5. 成员修改他的CSS时, $ c> ts - 再次只需要一个请求

  1. Default CSS is: /common/css.css
  2. Member customize CSS, now <link /> elements points to /user-specific/123.css?ts=123123123. 123 is of course an identifier of the member, and ts parameter contains a timestamp - a date of last CSS modification
  3. Make sure that your CSS generator sets proper HTTP headers responsible for client-side caching
  4. User browser request a CSS file - server replies with simple 304 Not Modified header - there is no need for any script execution or contents download
  5. When member modifies his CSS then you just update ts - once again just a single request is needed

这篇关于生成动态CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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