0

I need to control CSS with a cookie:

  • When the user chooses a style through a control I include on all of the pages, that setting needs to persist until the user changes it or the cookie expires
  • The default style nor a FOUC should occur when the user returns
  • No jquery or other library or framework
  • Works inIE, Firefox, Chrome, Opera, Safari on Windows; the last four on MacOS; Safari on iOS; Firefox and Chrome on Linux)
  • Bind web font used to a specific @class attribute
  • Buttons shrinkwrap their text value
  • Checkbox to toggle styles and show cookie state

My first strategy was to set an onload handler on the <body> element. I've seen discussion of at least two other approaches:

  • document.write to create a <link> to a stylesheet in the <head> as the page is being built.
  • sitewizard.com creates a set of small stylesheets and lets the user set one at a time to be active.

I'd be grateful for advice about choosing a strategy that is easy to code and maintain and that provides the functionality I need in the browsers I need to support.

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
obdurodon
  • 51
  • 8
  • You might try reposting this question on http://programmers.stackexchange.com – Kevin Bedell Jun 27 '12 at 22:55
  • @KevinBedell - Why are you pointing the OP to programmers? Did you read the programmers FAQ to see if it fits? – Oded Jun 28 '12 at 19:45
  • 'programmers' describes itself as the place for "professional programmers interested in conceptual questions about software development". The fact that the OP is looking "for advice about choosing a strategy" made me feel it was a better fit there. Do you disagree? – Kevin Bedell Jun 28 '12 at 19:47
  • Thanks, Kevin. I cross-posted, as you suggested, and then took it down, following Oded's admonition. I didn't mean to start a debate about venues or to transgress protocol or to step on any toes; I was just hoping for a bit of programming guidance. Perhaps someone will respond here ... – obdurodon Jun 28 '12 at 20:08

1 Answers1

1

Use a combination of techniques to avoid the root cause, which is repaints and reflows:

References

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265