Skip to content

Commit

Permalink
⭐ removing md5 signatures from minified assets
Browse files Browse the repository at this point in the history
  • Loading branch information
tracend committed Sep 28, 2015
1 parent 969f1e2 commit 93cd658
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions app/helpers/minify.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,22 @@ function css( $dom=false, $file=false ){
foreach ($el as $group=>$styles){
// get the raw css
$css = "";
$md5 = "";
//$md5 = "";
foreach ($styles as $style){
$result = $http->execute( $style );
if( $result && !empty($result) ){
$css .= $result;
}
}
// get the signature
$md5 .= md5($css);
//$md5 .= md5($css);
// remove comments
$css = $this->removeCommentsCSS($css);
// strip whitspace
$css = $this->trimWhitespace($css);
$this->_content[$group] = $css;
$this->_srcs[$group] = $cache_path ."$group.$md5.min.css";
//$this->_srcs[$group] = $cache_path ."$group.$md5.min.css";
$this->_srcs[$group] = $cache_path ."$group.css";
}

// remove the 'old' link tags
Expand Down Expand Up @@ -217,7 +218,7 @@ function less( $dom=false, $file=false ){
foreach ($target as $tag){
// get the raw css
$css = "";
$md5 = "";
//$md5 = "";
$href = $tag->getAttribute('href');
// check if it's a local url
$local = (substr($href, 0, 4) !== "http");
Expand All @@ -230,13 +231,14 @@ function less( $dom=false, $file=false ){

$css = $less->compile( $result );
// get the signature
$md5 = md5($css);
//$md5 = md5($css);
// remove comments
$css = $this->removeCommentsCSS($css);
// strip whitspace
$css = $this->trimWhitespace($css);
$this->_content[] = $css;
$filename = basename($href, ".less").".$md5.min.css";
//$filename = basename($href, ".less").".$md5.min.css";
$filename = basename($href, ".less").".css";
$this->_srcs[] = $cache_path . $filename;

// always leave the less link tags as markup - will be parced by the css()
Expand Down Expand Up @@ -482,7 +484,7 @@ function compileJS( $scripts ){
// sort results
//ksort_recursive( $minify );
// record signature
$md5 = "";
//$md5 = "";
$cache_path = $this->cache->getPath() ."/$baseUrl";
// FIX: create the dir if not available
if( !is_dir( $cache_path ) ) mkdir($cache_path, 0775, true);
Expand Down Expand Up @@ -512,13 +514,15 @@ function compileJS( $scripts ){
//$md5 .= md5_file($file);
}
// compress signatures of all files
$md5 = md5( $result );
//$md5 = md5( $result );
//contents of each group are saved in a tmp file
$tmp_file = $cache_path . "tmp.$md5.js";
//$tmp_file = $cache_path . "tmp.$md5.js";
$tmp_file = $cache_path . "tmp.js";
file_put_contents($tmp_file, $result);
// add tmp file
$min->add( $tmp_file );
$min->setFile( "$name.$md5.min" );
//$min->setFile( "$name.$md5.min" );
$min->setFile( "$name" );
if( !DEBUG){
$min->quiet()
->hideDebugInfo();
Expand All @@ -543,7 +547,7 @@ function compileJS( $scripts ){
$min->write();

// add the signature in the group
$scripts[$name][]["data"]["md5"] = $md5;
//$scripts[$name][]["data"]["md5"] = $md5;

}

Expand All @@ -558,11 +562,12 @@ function requireJS( $scripts, $dom ){
//$first = current($group);
$attr = $this->groupAttributes($group);
// signature of file/group
$md5 = ( !empty( $attr['data']['md5'] ) ) ? $attr['data']['md5'] : false;
//$md5 = ( !empty( $attr['data']['md5'] ) ) ? $attr['data']['md5'] : false;
// get file of the group
if( $attr['data']['minify'] ) {
$file = $GLOBALS['client']['require']['baseUrl'] . $name;
$file .= ( $md5 ) ? ".". $md5 .".min.js" : ".min.js";
//$file .= ( $md5 ) ? ".". $md5 .".min.js" : ".min.js";
$file .= ".js";
$file = cdn( $file );
} else {
$file = $attr["src"];
Expand All @@ -588,10 +593,9 @@ function requireJS( $scripts, $dom ){
}

// if there is a signature we'll have to create a new path for the group
if ( $md5 ){
$GLOBALS['client']['require']['paths'][$name] = substr( $file, 0, -3);

}
//if ( $md5 ){
// $GLOBALS['client']['require']['paths'][$name] = substr( $file, 0, -3);
//}

// push the name of the groups as the dependency
array_push( $GLOBALS['client']['require']['deps'], $name);
Expand Down Expand Up @@ -700,4 +704,4 @@ function setCache($path, $content){

}

?>
?>

0 comments on commit 93cd658

Please sign in to comment.