Created
April 6, 2011 20:22
-
-
Save samt/906441 to your computer and use it in GitHub Desktop.
CSS Generator
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
# | |
# CSS Generator | |
# | |
# Scans a directory for all the CSS and compiles them into a single, compressed | |
# document for easy and quick access from the client side. Also sends headers | |
# to ensure that the document will not be loaded more than every 2 days. | |
# | |
<Files .htaccess> | |
Order Allow,Deny | |
Deny from all | |
</files> | |
# | |
# Set some headers to ensure speed | |
# | |
<Files stylesheet.css> | |
Header set Cache-Control "max-age=172800, must-revalidate" | |
</files> | |
RewriteEngine On | |
# | |
# Rewrite to cssgen.php for generation | |
# | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_URI} /stylesheet\.css$ | |
RewriteRule . cssgen.php [L] |
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 | |
// | |
// CSS Cacher and compressor | |
// | |
$path = dirname(__FILE__); | |
$buffer = ''; | |
foreach(glob("*.css") as $file) | |
{ | |
$buffer .= file_get_contents($file); | |
} | |
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); | |
$buffer = str_replace(array("\t", "\r\n", "\r", "\n", ' ', ' ', ' '), '', $buffer); | |
$buffer = str_replace(array(': ', ' :', ', ', ' {', ';}'), array(':', ':', ',', '{', '}'), $buffer); | |
header("content-type: text/css; charset: UTF-8"); | |
echo $buffer; | |
@file_put_contents($path . '/stylesheet.css', $buffer); | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment