Graphics Programs Reference
In-Depth Information
One drawback to using HTTP headers to serve stylesheets is that it won't work in either
Internet Explorer or Safari. h at's why this technique is very rarely used to serve up CSS on
public Web sites. It's i ne in a development environment, of course, as long as you're using
Firefox or Opera as your development browser.
Now, suppose you either don't run Apache or can't mess with its coni guration, but still want
to do this.
If you're on an IIS server, you can send CSS via HTTP headers using the directions available
at http://technet.microsoft.com/en-us/library/cc753133(WS.10).aspx .
You can do it either through the IIS Manager interface or from the command line.
If you're using PHP for all your pages, on the other hand, then you don't have to mess with the
server coni guration at all, though you do have to add a PHP directive to every page that you
want to show the staging-server styles. As a bonus, this approach also works in all browsers.
h e simplest way is to add the following in each page's head element:
<? php if ($_ SERVER['HTTP_HOST'] == " staging.example.com") { ?>
< link rel= " stylesheet " href= " /staging.css " type= " text/css " />
<?php } ? >
h us you simply write out a link to a stylesheet, and if there's a browser that won't support
that, it isn't going to show you any CSS anyway.
106
h at works great for any i le served of of staging.example.com . A more robust solution,
one that works from any server with a certain string in its domain name or even from a local
development server running on your personal machine, looks like this:
<? php
if(preg_match(" / staging|test|dev|localhost|127\.0\.0\.1 / " , $_ SERVER['HTTP_
HOST'])) { ?>
< link rel= " stylesheet " href= " /staging.css " type= " text/css " />
<?php } ? >
You could also use PHP to conditionally emit HTTP headers to bring in a stylesheet; but
honestly, if you're already doing the server detection on each page, then you may as well just
write out the link element.
Similar approaches no doubt exist for the wide variety of Web development languages out
there. h e above code should provide a good start toward working out the details.
My thanks to Zachary Johnson ( http://www.zachstronaut.com/ ) and Alan Hogan
( http://alanhogan.com/ ) for their PHP contributions, and Peter Wilson ( http://
peterwilson.cc/ ) for pointing me to the IIS directions. Gentlemen and scholars all.
 
Search WWH ::




Custom Search