生成动态 CSS

发布于 2024-09-16 01:15:36 字数 225 浏览 9 评论 0原文

处理用户定制的样式的最佳方法是什么?作为我正在寻找的结果的一个示例,这就足够了:

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

但是,将 CSS 作为视图提供似乎会在不断请求的文件中造成大量开销,因此这可能不是一个好的解决方案。

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

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 }};
}

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月无声 2024-09-23 01:15:36

但是,将 CSS 作为视图提供似乎会在不断请求的文件中造成大量开销,因此这可能不是一个好的解决方案。

如果您生成一次 CSS 会怎样?

  1. 默认CSS为:/common/css.css
  2. 会员自定义CSS,现在元素指向/user-specific/123.css? ts=123123123123 当然是成员的标识符,ts 参数包含时间戳 - 最后一次 CSS 修改的日期
  3. 确保您的 CSS 生成器设置了对客户端负责的正确 HTTP 标头- 端缓存
  4. 用户浏览器请求 CSS 文件 - 服务器使用简单的 304 Not Modified 标头进行回复 - 无需执行任何脚本或下载内容
  5. 当成员修改其 CSS 时,您只需更新 ts - 再次只需要一个请求

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.

And what if you would generate that CSS once?

  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
风月客 2024-09-23 01:15:36

像平常一样通过视图动态执行 CSS,但使用积极的缓存,以便它加载速度很快。

Do the CSS dynamically via a view as normal, but use aggressive caching so that it loads quickly.

滥情哥ㄟ 2024-09-23 01:15:36

你可以尝试 django mediagenerato,实际上我读了这个问题,我正在寻找像你一样的解决方案,然后我发现 Django-mediagenerator

我还没有尝试过,但它似乎是一个解决方案。

You can try django mediagenerato, actually I read this Q and I was searching for solution like you, then I found that Django-mediagenerator

I didn't tried it yet but it seams to be a solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文