@@ -4,8 +4,8 @@ discard block |
||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | function ao_js_snippetcache($jsin,$scriptname) { |
| 7 | - // load speedupper conditionally (true by default?) |
|
| 8 | - if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 7 | + // load speedupper conditionally (true by default?) |
|
| 8 | + if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 9 | 9 | if (strpos($scriptname,"min.js")===false) { |
| 10 | 10 | $md5hash = "snippet_".md5($jsin); |
| 11 | 11 | $ccheck = new autoptimizeCache($md5hash,'js'); |
@@ -30,71 +30,71 @@ discard block |
||
| 30 | 30 | // do some housekeeping here to remove comments & linebreaks and stuff |
| 31 | 31 | $scriptsrc=preg_replace("#^\s*\/\/.*$#Um","",$jsin); |
| 32 | 32 | $scriptsrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$scriptsrc); |
| 33 | - $scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc); |
|
| 33 | + $scriptsrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $scriptsrc); |
|
| 34 | 34 | |
| 35 | - if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) { |
|
| 36 | - $scriptsrc.=";"; |
|
| 37 | - } |
|
| 35 | + if ((substr($scriptsrc,-1,1)!==";")&&(substr($scriptsrc,-1,1)!=="}")) { |
|
| 36 | + $scriptsrc.=";"; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - if (get_option("autoptimize_js_trycatch")==="on") { |
|
| 40 | - $scriptsrc="try{".$scriptsrc."}catch(e){}"; |
|
| 41 | - } |
|
| 39 | + if (get_option("autoptimize_js_trycatch")==="on") { |
|
| 40 | + $scriptsrc="try{".$scriptsrc."}catch(e){}"; |
|
| 41 | + } |
|
| 42 | 42 | } |
| 43 | 43 | return $scriptsrc; |
| 44 | - } |
|
| 44 | + } |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function ao_css_snippetcache($cssin,$filename) { |
| 48 | - // load speedupper conditionally (true by default?) |
|
| 49 | - if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 50 | - $md5hash = "snippet_".md5($cssin); |
|
| 51 | - $ccheck = new autoptimizeCache($md5hash,'css'); |
|
| 52 | - if($ccheck->check()) { |
|
| 53 | - $stylesrc = $ccheck->retrieve(); |
|
| 54 | - } else { |
|
| 55 | - if (strpos($filename,"min.css")===false) { |
|
| 56 | - if (class_exists('Minify_CSS_Compressor')) { |
|
| 57 | - $tmp_code = trim(Minify_CSS_Compressor::process($cssin)); |
|
| 58 | - } else if(class_exists('CSSmin')) { |
|
| 59 | - $cssmin = new CSSmin(); |
|
| 60 | - if (method_exists($cssmin,"run")) { |
|
| 61 | - $tmp_code = trim($cssmin->run($cssin)); |
|
| 62 | - } elseif (@is_callable(array($cssmin,"minify"))) { |
|
| 63 | - $tmp_code = trim(CssMin::minify($cssin)); |
|
| 64 | - } |
|
| 65 | - } |
|
| 48 | + // load speedupper conditionally (true by default?) |
|
| 49 | + if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 50 | + $md5hash = "snippet_".md5($cssin); |
|
| 51 | + $ccheck = new autoptimizeCache($md5hash,'css'); |
|
| 52 | + if($ccheck->check()) { |
|
| 53 | + $stylesrc = $ccheck->retrieve(); |
|
| 54 | + } else { |
|
| 55 | + if (strpos($filename,"min.css")===false) { |
|
| 56 | + if (class_exists('Minify_CSS_Compressor')) { |
|
| 57 | + $tmp_code = trim(Minify_CSS_Compressor::process($cssin)); |
|
| 58 | + } else if(class_exists('CSSmin')) { |
|
| 59 | + $cssmin = new CSSmin(); |
|
| 60 | + if (method_exists($cssmin,"run")) { |
|
| 61 | + $tmp_code = trim($cssmin->run($cssin)); |
|
| 62 | + } elseif (@is_callable(array($cssmin,"minify"))) { |
|
| 63 | + $tmp_code = trim(CssMin::minify($cssin)); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - if (!empty($tmp_code)) { |
|
| 68 | - $stylesrc = $tmp_code; |
|
| 69 | - unset($tmp_code); |
|
| 70 | - } else { |
|
| 71 | - $stylesrc = $cssin; |
|
| 72 | - } |
|
| 73 | - } else { |
|
| 74 | - // .min.css -> no heavy-lifting, just some cleanup |
|
| 75 | - $stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin); |
|
| 76 | - $stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc); |
|
| 77 | - $stylesrc=autoptimizeStyles::fixurls($filename,$stylesrc); |
|
| 78 | - } |
|
| 79 | - if (!empty($filename)) { |
|
| 80 | - // don't cache inline CSS to avoid risk of cache-explosion |
|
| 81 | - $ccheck->cache($stylesrc,'text/css'); |
|
| 82 | - } |
|
| 83 | - unset($ccheck); |
|
| 84 | - } |
|
| 85 | - return $stylesrc; |
|
| 86 | - } |
|
| 67 | + if (!empty($tmp_code)) { |
|
| 68 | + $stylesrc = $tmp_code; |
|
| 69 | + unset($tmp_code); |
|
| 70 | + } else { |
|
| 71 | + $stylesrc = $cssin; |
|
| 72 | + } |
|
| 73 | + } else { |
|
| 74 | + // .min.css -> no heavy-lifting, just some cleanup |
|
| 75 | + $stylesrc=preg_replace("#^\s*\/\*[^!].*\*\/\s?#Us","",$cssin); |
|
| 76 | + $stylesrc=preg_replace("#(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+#", "\n", $stylesrc); |
|
| 77 | + $stylesrc=autoptimizeStyles::fixurls($filename,$stylesrc); |
|
| 78 | + } |
|
| 79 | + if (!empty($filename)) { |
|
| 80 | + // don't cache inline CSS to avoid risk of cache-explosion |
|
| 81 | + $ccheck->cache($stylesrc,'text/css'); |
|
| 82 | + } |
|
| 83 | + unset($ccheck); |
|
| 84 | + } |
|
| 85 | + return $stylesrc; |
|
| 86 | + } |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // try to warm (snippet) cache when AO cache is cleared |
| 90 | 90 | function ao_speedup_warmcache() { |
| 91 | - // load speedupper conditionally (true by default?) |
|
| 92 | - if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 93 | - error_log("speedupper triggered"); |
|
| 94 | - $warmCacheUrl = site_url()."/?ao_speedup_cachebuster=".rand(1,100000); |
|
| 95 | - $warmCache = @wp_remote_get($warmCacheUrl); |
|
| 96 | - unset($warmCache); |
|
| 97 | - } |
|
| 91 | + // load speedupper conditionally (true by default?) |
|
| 92 | + if ( apply_filters('autoptimize_filter_speedupper', true) ) { |
|
| 93 | + error_log("speedupper triggered"); |
|
| 94 | + $warmCacheUrl = site_url()."/?ao_speedup_cachebuster=".rand(1,100000); |
|
| 95 | + $warmCache = @wp_remote_get($warmCacheUrl); |
|
| 96 | + unset($warmCache); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | add_filter('autoptimize_css_individual_style','ao_css_snippetcache',10,2); |