views:

26

answers:

2

I'm just trying to figure out the best approach here... my consideration is that I'd like my users to be able to customize the colors of certain elements on the page. These are not pre-made css they can choose from, but rather styles that can be edited using javascript to change the style, so they cannot be "pre-made" into separate style sheets. I am also generating the css into a cache directory since I am generating the css through a PHP script.

I am thinking that, perhaps I should:

1) If cached css file doesn't exist, create css file using the website default style settings.

2) If cached css file does exist, check if user has custom settings, if so, edit the cache file before displaying it.

Btw, when I refer to "cached file" I mean the PHP generated css document.

My goal is to prevent the need to have PHP re-generate the css file each time, whilst still allowing users, when logged in, to have their customized css settings applied. I will store these settings in a database most likely so when they return it is saved for them when they login.

A: 

Why not insert the customizations as inline CSS, that way it will surely override and caching will not be an issues.

Dustin Laine
That's true. I could have the default css style made, and then, if the user has any settings existing, I create a second css file each time for the user only overriding the modified styles. I think that's what you meant... I'm not good with terms eg. inlineThanks!
Joe
That would work, I meant add to the elements e.g. <div style="background-color: green;"></div>. Either way will work.
Dustin Laine
A: 

If you store the setting in a DB, PHP will have for sure to do something anyway because only PHP (I mean server side script) can get data from the DB. So at such point I wouldn't mind to let PHP also write down the CSS part specific for the customers inside the CSS file or if it's a small part that simply chaNges some of the many styles PHP could write them directly into the head section of the HTML pages.

If you want to do everything via JS without using PHP at all, you could store the CSS preferences in cookies, but if user cleans up his browser's cache he will loose all his styles preferences.

Marco Demajo
I'd prefer doing it with PHP since javascript would rely on cookies if used alone. I could have created separate css files for each user and cache those too, but it seems like overkill since their custom settings wouldn't be all that much extra css to load each time. If I am desparate to save on bandwidth/server load then obviously it wouldn't hurt to create a cache per each user and when they update their settings just replace their cache file.
Joe