Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
PHP: CSS Asset Pipeline
<?php
$files = [
// Insert Files Here
];
$str = '';
function combine_file_contents($filename, $str)
{
if (file_exists($filename)) {
$str .= file_get_contents($filename) . "\r\n";
return $str;
} else {
return $str;
}
}
foreach($files as $style) {
$str = combine_file_contents($style, $str);
}
$ETag = sha1($str);
/* Set Headers */
header('Content-Type: text/css');
header('ETag: ' . $ETag);
/* Output CSS */
echo $str;
Owner

davidcraig commented Mar 31, 2017

Simply add css files you wish to source into the $files array, then you can <link rel="stylesheet" src="css.php" type="text/css" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment