Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...