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.

Previous
Dodge It
Next
Which typefaces do you use on ShaunInman.com?
Author
Shaun Inman
Posted
August 20th, 2005 at 8:15 am
Categories
CSS
PHP
Web
CSS-SSC
Comments
017 (Now closed)

017 Comments

001

Bravo! Bravo!

… now if only we could get that calculations engine …

; )

Author
Silus Grok
Posted
Aug 20th, 2005 6:50 am
002

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?

Author
Krijn Hoetmer
Posted
Aug 20th, 2005 6:58 am
003

Nice, now I’ll need to install that :)

Author
Oliver Zheng
Posted
Aug 23rd, 2005 11:01 pm
004

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…

Author
Boris Anthony
Posted
Aug 25th, 2005 12:42 pm
005

Yeah, I think a products page would serve you well. You certainly are productive enough! Maybe com/ponents?

Author
Andrew
Posted
Aug 25th, 2005 12:47 pm
006

ShortStat is no longer supported.

Author
Shaun Inman
Posted
Aug 25th, 2005 1:10 pm
007

Just wondering… Which license is your code licensed under ?

Author
roger
Posted
Aug 27th, 2005 7:57 am
008

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.

Author
Shaun Inman
Posted
Aug 27th, 2005 9:55 am
009

Where’s your vendor prefix? And why don’t you using the functional notation for including the constants? The syntax should be more like:

@-inman-server constants {
    linkColor: #AB6666;
    linkColorHover: #710101;
    }
a { color: -inman-constant(linkColor); }
a:hover { color: -inman-constant(linkColorHover); }

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.

Author
Lachlan Hunt
Posted
Aug 31st, 2005 4:25 pm
010

Hmmm, I really don’t understand why you don’t simply use PHP for the stylesheet …

In your .htaccess:

AddType application/x-httpd-php .css

And of you go, full power of PHP in your css file.

in style.css: in a php section at the top:

$linkColor = #AB6666;
$linkColorHover = #710101;

later:

a { color: < ? echo $linkColor); ?>; }
a:hover { color: < ? echo $linkColorHover); ?>; }

You have the full power of PHP now, so you can everything that php can.

Author
Sascha Ebach
Posted
Sep 2nd, 2005 6:37 am
011

I agree with comments regarding vendor prefixing, at least a minimal one. A few more ideas:

  1. A programmatic way to specify which file would be @-ssc-server included. This would allow multiple users to have different styles.
  2. Allow constants to be set to existing constants (for completeness).
  3. It’d be nice to be able to define IMG src attributes in the CSS, allowing the script (perhaps a separate one included in each page) to dole these out depending on the current style sheet. This would let us move the remaining bits of style (the srcs of IMG elements) into the CSS, eliminating the need for traditional background-image IR techniques.
Author
Steve Clay
Posted
Sep 16th, 2005 5:36 am
012

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

Author
Cody
Posted
Sep 17th, 2005 12:00 am
013

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.

Author
Stephen
Posted
Sep 18th, 2005 8:02 pm
014

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.

Author
Richard Taytor
Posted
Sep 28th, 2005 3:36 pm
015

Cody’s site is down — is the newer version with optimizer being hosted anywhere else?

Author
Mark
Posted
Oct 29th, 2005 9:20 pm
016

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

Author
Alexandre Martini
Posted
Dec 19th, 2005 4:04 am
017

anyone can reupload the cody version with CSS Optimizer somewhere ?

Author
mutui
Posted
Dec 20th, 2005 12:21 pm