A Quick CSS SSC Update
Update
Interested in CSS-SSC? You may be more interested in the CSS Server-side Pre-processor.
This update (with samples) rolls in a clever hack offered by Zac that allows one constant name to include another without conflict. Previously the following code would not work as expected:
@server constants {
linkColor: #AB6666;
linkColorHover: #710101;
}
a { color: linkColor; }
a:hover { color: linkColorHover; }
The replacement would have resulted in:
a { color: #AB6666; }
a:hover { color: #AB6666Hover; }
Not very helpful. This update produces the expected:
a { color: #AB6666; }
a:hover { color: #710101; }
I also added a check for apache_request_headers before calling it to avoid potential errors/warnings that a number of people were encountering.
Please see the previous article for CSS Server-side Constants’ complete syntax and installation instructions.
017 Comments
Bravo! Bravo!
… now if only we could get that calculations engine …
; )
With ‘large’ CSS files Gecko based browsers still have some difficulties with caching. The problem doesn’t appear in the example file (base.css), but refreshing a larger file a few times gives some weird results. Any idea what causes this?
Nice, now I’ll need to install that :)
Dude, sorry but I just spent 20 minutes looking for where to download Shortstat… I sorta stepped my way though from a linked b34 link up to 36 … you must really not want people to download it…
Yeah, I think a products page would serve you well. You certainly are productive enough! Maybe com/ponents?
ShortStat is no longer supported.
Just wondering… Which license is your code licensed under ?
The formal line: CSS-SSV is provided strictly on an as is basis. You are soley responsible and liable for any damage you do to your website or server.
Love it, use it, modify it. I would appreciate it if you kept the credit and link back to my site intact but it’s not necessary.
Where’s your vendor prefix? And why don’t you using the functional notation for including the constants? The syntax should be more like:
You can use whatever prefix you like, this is just an example. @-ssc-server may be another good option. See my comment over on Eric Meyer’s blog entry.
Hmmm, I really don’t understand why you don’t simply use PHP for the stylesheet …
In your .htaccess:
And of you go, full power of PHP in your css file.
in style.css: in a php section at the top:
later:
You have the full power of PHP now, so you can everything that php can.
I agree with comments regarding vendor prefixing, at least a minimal one. A few more ideas:
I have made a version of this that has a built in CSS optimizer for removing whitespace and comments, and even creating shorthand. It also has a few more options and better stats. Check it out: pixeljunkies.com/forum/viewtopic.php?id=148
Sascha, I would love to do something like that, but wouldn’t that cause the CSS file to be parsed on every page load rather than just cached once? I wouldn’t recommend doing that with a large CSS file, but with a small file just for colors that’s probably a very flexible way to go.
Thanks so much for CSS-SSC! I noticed that the script returns errors for files not found. It seems reasonable that it should instead redirect to 404.
Cody’s site is down — is the newer version with optimizer being hosted anywhere else?
Hi,
I was having the same caching problems Krijn had, using Firefox. The solution I found is disabling the caching management in the script. I don’t know what other problems you may encounter after doing this, so here it goes (until someone finds that answer).
Just comment the following lines:
if (!isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’])) { $header = apache_request_headers(); if (isset($header[‘If-Modified-Since’])) { $_SERVER[‘HTTP_IF_MODIFIED_SINCE’] = $header[‘If-Modified-Since’]; } } if (isset($_SERVER[‘HTTP_IF_MODIFIED_SINCE’]) && $dt
anyone can reupload the cody version with CSS Optimizer somewhere ?