Skip to content

Instantly share code, notes, and snippets.

@putzflorian
Created June 18, 2013 15:06
Show Gist options
  • Select an option

  • Save putzflorian/5806150 to your computer and use it in GitHub Desktop.

Select an option

Save putzflorian/5806150 to your computer and use it in GitHub Desktop.
compress js files with php
<?php
$jsFiles = array(....DEINE JS FILES ...);
$failed = array();
$checksum = "";
foreach($jsFiles as $file){
$realPath = PIMCORE_DOCUMENT_ROOT . $file;
if(file_exists($realPath)) {
$checksum .= ($file . "-" . filemtime($realPath) . "~~");
} else {
echo "Failed to load " . $file . " from filesystem - quit.";
exit;
}
}
$checksum = md5($checksum);
$cacheFile = PIMCORE_TEMPORARY_DIRECTORY . "/js-cache-" . $checksum . ".js";
if(!file_exists($cacheFile)) {
$jsContents = "";
foreach($jsFiles as $file){
$realPath = PIMCORE_DOCUMENT_ROOT . $file;
if(file_exists($realPath)) {
$jsContents .= file_get_contents($realPath) . "\n\n\n\n";
}
}
file_put_contents($cacheFile, $jsContents);
}
?>
<script type="text/javascript" src="<?= str_replace(PIMCORE_DOCUMENT_ROOT, "", $cacheFile); ?>"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment