Reputation: 8413
I want to implement a simple feature into my node.js/express app that allows the users (registered and nonregistered) to quickly change some settings in the CSS theme.
Is there a way of implementing it in a way that I don't have to record the user's preference into the db, instead the app just remembers the preference of the current browsing session and shows a different CSS theme depending on what the user selected.
And I need these styles to not be in a separate CSS file, but some kind of adjustment to the existing ones.
What would be the best way to implement it?
I thought about adding a few style modifications in a separate CSS file and then when the user selects a different theme, recording it as the current preference and loading that additional css for those users.
Do you think it's a good way or there's a more efficient one?
Upvotes: 0
Views: 497
Reputation: 91
Look into LocalStorage (available in just about every modern browser) for storing the preference, or instead store the preference in a non-expiring cookie. The first approach is best if your preferences are complex (like overriding individual elements) and the second if they're simpler (like just one file override).
As for the updated CSS, don't modify existing files. Use the cascading nature of the language, which is built for overrides. In other words, inline the changed CSS into your html. It will usually take precedence over separate CSS files unless individual rule weights are different for some reason (like more specific selectors, which increase rule weight/priority).
Upvotes: 1