在数据库中存储每个用户的颜色数组
我正在考虑网站的用户可配置配色方案的问题。该站点当前拥有一组平面 CSS 文件,用户可以选择这些文件(选择内容作为列存储在 SQL 数据库的用户表中)。这导致了维护问题,因为更新文件来扩展站点的 CSS 是不可行的。
特别是,我希望用户能够选择一组 css 选择器的颜色值。也就是说,在伪代码中,
body {
background-color : <% print user_bg_color %>;
}
我的问题与实现此类 CSS 生成的机制无关。相当,
是否有存储此类值集合的标准实践或最佳方法?
[编辑]
如果没有标准方法,有哪些技巧?
[/编辑]
任何此类技术都应该是可扩展的,因为对网站 CSS 的进一步修改将允许网站管理员添加新变量。目前,约有 30 种配色方案,每种配色方案包含 90 个变量,约有 35,000 名用户。
I am considering the problem of user-configurable color schemes for a website. The site currently has a collection of flat CSS files, which are selectable by users (selection is stored as a column in the user table of a SQL database). This has led to a maintenance problem, in that updating the files to extend the site's CSS is not feasible.
In particular, there is a collection of css selectors that I would like users to be able to choose color values for. That is, in pseudo-code,
body {
background-color : <% print user_bg_color %>;
}
My question is not concerned with the mechanics of implementing such CSS generation. Rather,
Is there a standard practice or best way for storing such a collection of values?
[EDIT]
If there is no standard way, what are some techniques?
[/EDIT]
Any such technique should be extendable, in the sense that further modification of the site's CSS would allow for the addition of new variables by the site admins. Currently, there are about 30 color schemes consisting of 90 variables each, and about 35,000 users.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为不一定有一个标准的方法,但对我来说显而易见和简单的是本质上是一个多对多表(尽管你的css变量名不一定独立存储在数据库中,除非你需要添加比变量名更多的数据):
这样您就可以轻松地为用户选择所有 css,或者独立地选择 user_id 和用户的 css_variable_name。
至少在 user_id 上放置一个索引。这应该会使性能相当快。 (由于所有重复项,您可能不希望在 css_variable_name 上使用一个,但两种方式都值得测试)
I don't think there is necessarily a standard way, but what seems obvious and simple to me is a essentially many-to-many table (although your css variable names aren't necessarily stored in the database independently, unless you need to add more data than the variable name) with:
This way you can easily select all the css for a user, or independently the user_id and css_variable_name for a user.
Put an index on user_id, at least. That should make performance decently fast. (You may don't want one on css_variable_name because of all the duplicates, but it would be worth testing both ways)