Last active
August 29, 2015 13:58
-
-
Save miwebguy/10283856 to your computer and use it in GitHub Desktop.
PHP CSS Stylesheet with variables and cache headers
This file contains hidden or 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