-
-
Save billcreswell/dec7ab1717dedaa90571 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adding Cache Headers and ETag to example: http://sperling.com/examples/pcss/ | |
*/ | |
class PHPStyle | |
{ | |
public static function setHeaders($filename="style.css",$type="text/css") | |
{ | |
$mod = date ("Y-m-d::H:i:s.", getlastmod()); | |
$etag = $filename.$mod; | |
$headers = apache_request_headers(); | |
$isCached = isset($headers['If-None-Match']) && $headers['If-None-Match']==$etag; | |
header("Content-type: $type"); | |
if ($isCached) { | |
header('HTTP/1.1 304 Not Modified'); | |
header("Cache-Control: max-age=604800"); | |
header("Pragma: cache"); | |
header("ETag: $etag"); | |
die(); | |
} else { | |
header("Etag: $etag"); | |
header("Pragma: cache"); | |
header("Cache-Control: max-age=604800"); | |
header("Content-Disposition: inline; filename=\"$filename\""); | |
} | |
} | |
} | |
$test = PHPStyle::setHeaders(); | |
$blue = "blue"; | |
$green = "green"; | |
$sheet = <<<CSS | |
/* --- start of css --- */ | |
h1 { | |
color: $blue; | |
font-weight: bold; | |
font-size: 1.2em; | |
text-align: left; | |
} | |
h2 { | |
color:$green; | |
} | |
/* --- end of css --- */ | |
CSS; | |
echo $sheet; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment