生成动态CSS [英] Generating dynamic 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?
- 默认CSS是:
/common/css.css
- 会员自定义CSS,现在
< link />
元素指向/ user- specific / 123。 css?ts = 123123123
。123
当然是成员的标识符,ts
参数包含时间戳 - 上次CSS修改的日期 - 确保您的CSS生成器设置了适当的HTTP标头,负责客户端缓存
- 用户浏览器请求CSS文件 - 服务器回复简单
304未修改
标题 - 无需任何脚本执行或内容下载 - 成员修改他的CSS时, $ c> ts - 再次只需要一个请求
- Default CSS is:
/common/css.css
- Member customize CSS, now
<link />
elements points to/user-specific/123.css?ts=123123123
.123
is of course an identifier of the member, andts
parameter contains a timestamp - a date of last CSS modification - Make sure that your CSS generator sets proper HTTP headers responsible for client-side caching
- 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 - When member modifies his CSS then you just update
ts
- once again just a single request is needed
这篇关于生成动态CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!