Generating dynamic CSS

后端 未结 3 1018
甜味超标
甜味超标 2020-12-16 14:59

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: {{         


        
相关标签:
3条回答
  • 2020-12-16 15:23

    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
    0 讨论(0)
  • 2020-12-16 15:33

    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.

    0 讨论(0)
  • 2020-12-16 15:43

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

    0 讨论(0)
提交回复
热议问题