Last active
October 5, 2015 22:17
-
-
Save tessguefen/81794bc0fbbf235ccc55 to your computer and use it in GitHub Desktop.
Minify CSS
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 | |
if (extension_loaded('zlib')) { | |
ob_start('ob_gzhandler'); | |
} | |
header ('content-type: text/css; charset: UTF-8'); | |
header ('cache-control: must-revalidate'); | |
$offset = 60 * 60; | |
$expire = 'expires: ' . gmdate ('D, d M Y H:i:s', time() + $offset) . ' GMT'; | |
header ($expire); | |
ob_start('compress'); | |
function compress($buffer) { | |
/* remove comments */ | |
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); | |
/* remove tabs, spaces, newlines, etc. */ | |
$buffer = str_replace(array("\r\n", "\r", "\n", "\t"), '', $buffer); | |
return $buffer; | |
} | |
/* css files for compression */ | |
include('minibasket.css'); | |
include('bootstrap.css'); | |
include('font-awesome.css'); | |
include('style.css'); | |
include('default.css'); | |
$etag = md5(ob_get_length()); | |
header('Etag: ' . $etag); | |
if (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { | |
header('HTTP/1.1 304 Not Modified'); | |
exit; | |
} | |
if (extension_loaded('zlib')) { | |
ob_end_flush(); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment