Created
June 18, 2013 15:06
-
-
Save putzflorian/5806150 to your computer and use it in GitHub Desktop.
compress js files with php
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 | |
| $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