Fast Velocity Minify - Version 2.5.2

Version Description

[2019.01.11] = * fixed a query monitor notice about mkdir * removed some legacy code * improvement for the "defer for pagespeed option", "ignore list" and "loadCSS" functionality * improvements for the merging of google fonts option * improvements for merging of JS and CSS files when server returns an HTML 404 page, but with HTTP 200 OK header instead

Download this release

Release Info

Developer Alignak
Plugin Icon 128x128 Fast Velocity Minify
Version 2.5.2
Comparing to
See all releases

Code changes from version 2.5.1 to 2.5.2

Files changed (3) hide show
  1. fvm.php +135 -112
  2. inc/functions.php +19 -42
  3. readme.txt +13 -6
fvm.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://fastvelocity.com
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
- Version: 2.5.1
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
@@ -88,12 +88,6 @@ $wp_home = site_url(); # get the current wordpress installation url
88
  $wp_domain = trim(str_ireplace(array('http://', 'https://'), '', trim($wp_home, '/')));
89
  $wp_home_path = ABSPATH;
90
 
91
- # cleanup, delete any minification files older than 45 days (most probably unused files)
92
- if ($handle = opendir($cachedir.'/')) {
93
- while (false !== ($file = readdir($handle))) { $file = $cachedir.'/'.$file; if (is_file($file) && time() - filemtime($file) >= 86400 * 45) { unlink($file); } }
94
- closedir($handle);
95
- }
96
-
97
  # default globals
98
  $fastvelocity_min_global_js_done = array();
99
  $fvm_collect_google_fonts = array();
@@ -106,11 +100,12 @@ $fvm_debug = get_option('fastvelocity_fvm_debug');
106
  ###########################################
107
 
108
  # options from the database, false if not set
109
- $ignore = array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_ignore', '')));
110
- $blacklist = array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_blacklist', '')));
111
- $ignorelist = array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_ignorelist', '')));
112
- $fvm_min_excludecsslist = array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_excludecsslist', '')));
113
- $fvm_min_excludejslist = array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_excludejslist', '')));
 
114
  $fvm_enable_purgemenu = get_option('fastvelocity_min_enable_purgemenu');
115
  $default_protocol = get_option('fastvelocity_min_default_protocol', 'dynamic');
116
  $disable_js_merge = get_option('fastvelocity_min_disable_js_merge');
@@ -1333,19 +1328,21 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1333
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1334
 
1335
  # generate cache, write log
1336
- file_put_contents($file.'.txt', $log);
1337
- file_put_contents($file, $code);
1338
- file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1339
-
1340
- # permissions
1341
- fastvelocity_fix_permission_bits($file.'.txt');
1342
- fastvelocity_fix_permission_bits($file);
1343
- fastvelocity_fix_permission_bits($file.'.gz');
1344
-
1345
- # brotli static support
1346
- if(function_exists('brotli_compress')) {
1347
- file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1348
- fastvelocity_fix_permission_bits($file.'.br');
 
 
1349
  }
1350
  }
1351
 
@@ -1515,19 +1512,21 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1515
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1516
 
1517
  # generate cache, write log
1518
- file_put_contents($file.'.txt', $log);
1519
- file_put_contents($file, $code);
1520
- file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1521
-
1522
- # permissions
1523
- fastvelocity_fix_permission_bits($file.'.txt');
1524
- fastvelocity_fix_permission_bits($file);
1525
- fastvelocity_fix_permission_bits($file.'.gz');
1526
-
1527
- # brotli static support
1528
- if(function_exists('brotli_compress')) {
1529
- file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1530
- fastvelocity_fix_permission_bits($file.'.br');
 
 
1531
  }
1532
  }
1533
 
@@ -1592,42 +1591,51 @@ if (count($ignorelist) > 0 && fastvelocity_min_in_arrayi($src, $ignorelist)) { r
1592
  # fix page editors
1593
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
1594
 
1595
- # get available nodes and add create with defer tag (if not async)
1596
- $dom = new DOMDocument();
1597
- libxml_use_internal_errors(true);
1598
- @$dom->loadHTML($tag);
1599
- $nodes = $dom->getElementsByTagName('script');
1600
- $tagdefer = '';
1601
- if ($nodes->length != 0) {
1602
- $node = $dom->getElementsByTagName('script')->item(0);
1603
- if (!$node->hasAttribute('async')) { $node->setAttribute('defer','defer'); };
1604
- $tagdefer = $dom->saveHTML($node);
1605
- }
1606
-
1607
- # when to defer, order matters
1608
- if($enable_defer_js == true) { return $tagdefer; }
1609
-
1610
- # return if no defer, and there's no defer for pagespeed... else pagespeed processing
1611
- if ($defer_for_pagespeed != true) { return $tag; } else {
1612
-
1613
- # return if there are linebreaks (will break document.write)
1614
- if (stripos($tag, PHP_EOL) !== false) { return $tag; }
1615
 
1616
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1617
  if (fvm_is_local_domain($src) !== true) { return $tag; }
1618
 
1619
-
1620
-
1621
- # print code if there are no linebreaks, or return
1622
- if(!empty($tagdefer)) {
1623
- $deferinsights = '<script type="text/javascript">if(navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($tagdefer).');}else{document.write('.json_encode($tag).');}</script>';
1624
- return preg_replace('#<script(.*?)>(.*?)</script>#is', $deferinsights, $tag);
1625
- }
1626
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1627
  # fallback
1628
- return $tag;
1629
- }
1630
-
1631
  }
1632
  ###########################################
1633
 
@@ -1950,19 +1958,21 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1950
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1951
 
1952
  # generate cache, write log
1953
- file_put_contents($file.'.txt', $log);
1954
- file_put_contents($file, $code);
1955
- file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1956
-
1957
- # permissions
1958
- fastvelocity_fix_permission_bits($file.'.txt');
1959
- fastvelocity_fix_permission_bits($file);
1960
- fastvelocity_fix_permission_bits($file.'.gz');
1961
-
1962
- # brotli static support
1963
- if(function_exists('brotli_compress')) {
1964
- file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1965
- fastvelocity_fix_permission_bits($file.'.br');
 
 
1966
  }
1967
  }
1968
 
@@ -2319,19 +2329,21 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
2319
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
2320
 
2321
  # generate cache, add inline css, write log
2322
- file_put_contents($file.'.txt', $log);
2323
- file_put_contents($file, $code); # preserve style tags
2324
- file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
2325
-
2326
- # permissions
2327
- fastvelocity_fix_permission_bits($file.'.txt');
2328
- fastvelocity_fix_permission_bits($file);
2329
- fastvelocity_fix_permission_bits($file.'.gz');
2330
-
2331
- # brotli static support
2332
- if(function_exists('brotli_compress')) {
2333
- file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
2334
- fastvelocity_fix_permission_bits($file.'.br');
 
 
2335
  }
2336
  }
2337
 
@@ -2389,8 +2401,8 @@ function fvm_add_loadcss() {
2389
 
2390
  echo <<<EOF
2391
  <script>
2392
- /*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
2393
- !function(n){"use strict";n.loadCSS||(n.loadCSS=function(){});var o=loadCSS.relpreload={};if(o.support=function(){var e;try{e=n.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),o.bindMediaToggle=function(t){var e=t.media||"all";function a(){t.media=e}t.addEventListener?t.addEventListener("load",a):t.attachEvent&&t.attachEvent("onload",a),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(a,3e3)},o.poly=function(){if(!o.support())for(var t=n.document.getElementsByTagName("link"),e=0;e<t.length;e++){var a=t[e];"preload"!==a.rel||"style"!==a.getAttribute("as")||a.getAttribute("data-loadcss")||(a.setAttribute("data-loadcss",!0),o.bindMediaToggle(a))}},!o.support()){o.poly();var t=n.setInterval(o.poly,500);n.addEventListener?n.addEventListener("load",function(){o.poly(),n.clearInterval(t)}):n.attachEvent&&n.attachEvent("onload",function(){o.poly(),n.clearInterval(t)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:n.loadCSS=loadCSS}("undefined"!=typeof global?global:this);
2394
  </script>
2395
  EOF;
2396
 
@@ -2398,12 +2410,15 @@ EOF;
2398
 
2399
  # fvm load async scripts with callback
2400
  function fvm_add_loadasync() {
 
 
2401
 
2402
  echo <<<EOF
2403
  <script>function loadAsync(e,a){var t=document.createElement("script");t.src=e,null!==a&&(t.readyState?t.onreadystatechange=function(){"loaded"!=t.readyState&&"complete"!=t.readyState||(t.onreadystatechange=null,a())}:t.onload=function(){a()}),document.getElementsByTagName("head")[0].appendChild(t)}</script>
2404
  EOF;
2405
 
2406
  }
 
2407
 
2408
 
2409
 
@@ -2477,9 +2492,6 @@ if($fvm_headers != false) {
2477
  ###########################################
2478
  function fastvelocity_min_defer_js_optimize($tag, $handle, $src) {
2479
  global $defer_for_pagespeed, $defer_for_pagespeed_optimize, $fvm_fix_editor, $fvmualist;
2480
-
2481
- # return if there are linebreaks (will break document.write)
2482
- if (stripos($tag, PHP_EOL) !== false) { return $tag; }
2483
 
2484
  # fix page editors
2485
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
@@ -2499,20 +2511,31 @@ if(substr($handle, 0, 4) != "fvm-" && $defer_for_pagespeed == true && $defer_for
2499
  $dom = new DOMDocument();
2500
  libxml_use_internal_errors(true);
2501
  @$dom->loadHTML($tag);
2502
- $nodes = $dom->getElementsByTagName('script');
2503
- $tagdefer = '';
2504
  if ($nodes->length != 0) {
2505
- $node = $dom->getElementsByTagName('script')->item(0);
2506
- if (!$node->hasAttribute('async')) { $node->setAttribute('defer','defer'); };
2507
- $tagdefer = $dom->saveHTML($node);
2508
- }
2509
-
2510
- # print code if there are no linebreaks, or return
2511
- if(!empty($tagdefer)) {
2512
- $deferinsights = '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($tag).');}</script>';
2513
- return preg_replace('#<script(.*?)>(.*?)</script>#is', $deferinsights, $tag);
 
 
 
 
 
 
 
 
 
 
 
 
2514
  }
2515
-
2516
  }
2517
 
2518
  # fallback
5
  Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations.
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
+ Version: 2.5.2
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
88
  $wp_domain = trim(str_ireplace(array('http://', 'https://'), '', trim($wp_home, '/')));
89
  $wp_home_path = ABSPATH;
90
 
 
 
 
 
 
 
91
  # default globals
92
  $fastvelocity_min_global_js_done = array();
93
  $fvm_collect_google_fonts = array();
100
  ###########################################
101
 
102
  # options from the database, false if not set
103
+ $ignore = array_filter(array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_ignore', ''))));
104
+ $blacklist = array_filter(array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_blacklist', ''))));
105
+ $ignorelist = array_filter(array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_ignorelist', ''))));
106
+ $fvm_min_excludecsslist = array_filter(array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_excludecsslist', ''))));
107
+ $fvm_min_excludejslist = array_filter(array_map('trim', explode(PHP_EOL, get_option('fastvelocity_min_excludejslist', ''))));
108
+
109
  $fvm_enable_purgemenu = get_option('fastvelocity_min_enable_purgemenu');
110
  $default_protocol = get_option('fastvelocity_min_default_protocol', 'dynamic');
111
  $disable_js_merge = get_option('fastvelocity_min_disable_js_merge');
1328
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1329
 
1330
  # generate cache, write log
1331
+ if(!empty($code)) {
1332
+ file_put_contents($file.'.txt', $log);
1333
+ file_put_contents($file, $code);
1334
+ file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1335
+
1336
+ # permissions
1337
+ fastvelocity_fix_permission_bits($file.'.txt');
1338
+ fastvelocity_fix_permission_bits($file);
1339
+ fastvelocity_fix_permission_bits($file.'.gz');
1340
+
1341
+ # brotli static support
1342
+ if(function_exists('brotli_compress')) {
1343
+ file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1344
+ fastvelocity_fix_permission_bits($file.'.br');
1345
+ }
1346
  }
1347
  }
1348
 
1512
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1513
 
1514
  # generate cache, write log
1515
+ if(!empty($code)) {
1516
+ file_put_contents($file.'.txt', $log);
1517
+ file_put_contents($file, $code);
1518
+ file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1519
+
1520
+ # permissions
1521
+ fastvelocity_fix_permission_bits($file.'.txt');
1522
+ fastvelocity_fix_permission_bits($file);
1523
+ fastvelocity_fix_permission_bits($file.'.gz');
1524
+
1525
+ # brotli static support
1526
+ if(function_exists('brotli_compress')) {
1527
+ file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1528
+ fastvelocity_fix_permission_bits($file.'.br');
1529
+ }
1530
  }
1531
  }
1532
 
1591
  # fix page editors
1592
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
1593
 
1594
+ # return if no defer selected
1595
+ if ($defer_for_pagespeed != true && $enable_defer_js != true) { return $tag; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1596
 
1597
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1598
  if (fvm_is_local_domain($src) !== true) { return $tag; }
1599
 
1600
+ # get available nodes and add create with defer tag (if not async)
1601
+ $dom = new DOMDocument();
1602
+ libxml_use_internal_errors(true);
1603
+ @$dom->loadHTML($tag);
1604
+ $nodes = $dom->getElementsByTagName('script');
1605
+ $newtag = '';
1606
+ if ($nodes->length != 0) {
1607
+ foreach ($nodes as $k=>$v) {
1608
+ $node = $dom->getElementsByTagName('script')->item($k);
1609
+ if ($node->hasAttribute('src')) {
1610
+
1611
+ # bypass if there are linebreaks (will break document.write)
1612
+ if (stripos($ntag, PHP_EOL) !== false || stripos($tag, 'navigator.userAgent.match') !== false) {
1613
+ $newtag.= $dom->saveHTML($node);
1614
+ } else {
1615
+ $ntagoriginal = $dom->saveHTML($node);
1616
+ if (!$node->hasAttribute('async')) { $node->setAttribute('defer','defer'); };
1617
+ $ntagdefer = $dom->saveHTML($node);
1618
+
1619
+ # enable defer globally, or for PSI only
1620
+ if($enable_defer_js == true && $defer_for_pagespeed != true) {
1621
+ $newtag.= $ntagprocessed;
1622
+ } else {
1623
+ $newtag.= '<script type="text/javascript">if(navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($ntagdefer).');}else{document.write('.json_encode($ntagoriginal).');}</script>';
1624
+ }
1625
+ }
1626
+ } else {
1627
+ $newtag.= $dom->saveHTML($node);
1628
+ }
1629
+ }
1630
+
1631
+ # print code if there are no linebreaks, or return
1632
+ if(!empty($newtag)) {
1633
+ return $newtag;
1634
+ }
1635
+ }
1636
+
1637
  # fallback
1638
+ return $tag;
 
 
1639
  }
1640
  ###########################################
1641
 
1958
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
1959
 
1960
  # generate cache, write log
1961
+ if(!empty($code)) {
1962
+ file_put_contents($file.'.txt', $log);
1963
+ file_put_contents($file, $code);
1964
+ file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
1965
+
1966
+ # permissions
1967
+ fastvelocity_fix_permission_bits($file.'.txt');
1968
+ fastvelocity_fix_permission_bits($file);
1969
+ fastvelocity_fix_permission_bits($file.'.gz');
1970
+
1971
+ # brotli static support
1972
+ if(function_exists('brotli_compress')) {
1973
+ file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
1974
+ fastvelocity_fix_permission_bits($file.'.br');
1975
+ }
1976
  }
1977
  }
1978
 
2329
  $log = "PROCESSED on ".date('r').PHP_EOL.$log."PROCESSED from ".home_url(add_query_arg( NULL, NULL )).PHP_EOL;
2330
 
2331
  # generate cache, add inline css, write log
2332
+ if(!empty($code)) {
2333
+ file_put_contents($file.'.txt', $log);
2334
+ file_put_contents($file, $code); # preserve style tags
2335
+ file_put_contents($file.'.gz', gzencode(file_get_contents($file), 9));
2336
+
2337
+ # permissions
2338
+ fastvelocity_fix_permission_bits($file.'.txt');
2339
+ fastvelocity_fix_permission_bits($file);
2340
+ fastvelocity_fix_permission_bits($file.'.gz');
2341
+
2342
+ # brotli static support
2343
+ if(function_exists('brotli_compress')) {
2344
+ file_put_contents($file.'.br', brotli_compress(file_get_contents($file), 9));
2345
+ fastvelocity_fix_permission_bits($file.'.br');
2346
+ }
2347
  }
2348
  }
2349
 
2401
 
2402
  echo <<<EOF
2403
  <script>
2404
+ /* loadCSS. [c]2017 Filament Group, Inc. MIT License */
2405
+ (function(w){if(!w.loadCSS)w.loadCSS=function(){};var rp=loadCSS.relpreload={};rp.support=function(){var ret;try{ret=w.document.createElement("link").relList.supports("preload")}catch(e){ret=false}return function(){return ret}}();rp.bindMediaToggle=function(link){var finalMedia=link.media||"all";function enableStylesheet(){if(link.addEventListener)link.removeEventListener("load",enableStylesheet);else if(link.attachEvent)link.detachEvent("onload",enableStylesheet);link.setAttribute("onload",null);link.media=finalMedia}if(link.addEventListener)link.addEventListener("load",enableStylesheet);else if(link.attachEvent)link.attachEvent("onload",enableStylesheet);setTimeout(function(){link.rel="stylesheet";link.media="only x"});setTimeout(enableStylesheet,3E3)};rp.poly=function(){if(rp.support())return;var links=w.document.getElementsByTagName("link");for(var i=0;i<links.length;i++){var link=links[i];if(link.rel==="preload"&&link.getAttribute("as")==="style"&&!link.getAttribute("data-loadcss")){link.setAttribute("data-loadcss", true);rp.bindMediaToggle(link)}}};if(!rp.support()){rp.poly();var run=w.setInterval(rp.poly,500);if(w.addEventListener)w.addEventListener("load",function(){rp.poly();w.clearInterval(run)});else if(w.attachEvent)w.attachEvent("onload",function(){rp.poly();w.clearInterval(run)})}if(typeof exports!=="undefined")exports.loadCSS=loadCSS;else w.loadCSS=loadCSS})(typeof global!=="undefined"?global:this);
2406
  </script>
2407
  EOF;
2408
 
2410
 
2411
  # fvm load async scripts with callback
2412
  function fvm_add_loadasync() {
2413
+ global $fvm_min_excludejslist;
2414
+ if($fvm_min_excludejslist != false && is_array($fvm_min_excludejslist) && count($fvm_min_excludejslist) > 0) {
2415
 
2416
  echo <<<EOF
2417
  <script>function loadAsync(e,a){var t=document.createElement("script");t.src=e,null!==a&&(t.readyState?t.onreadystatechange=function(){"loaded"!=t.readyState&&"complete"!=t.readyState||(t.onreadystatechange=null,a())}:t.onload=function(){a()}),document.getElementsByTagName("head")[0].appendChild(t)}</script>
2418
  EOF;
2419
 
2420
  }
2421
+ }
2422
 
2423
 
2424
 
2492
  ###########################################
2493
  function fastvelocity_min_defer_js_optimize($tag, $handle, $src) {
2494
  global $defer_for_pagespeed, $defer_for_pagespeed_optimize, $fvm_fix_editor, $fvmualist;
 
 
 
2495
 
2496
  # fix page editors
2497
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
2511
  $dom = new DOMDocument();
2512
  libxml_use_internal_errors(true);
2513
  @$dom->loadHTML($tag);
2514
+ $nodes = $dom->getElementsByTagName('script');
2515
+ $newtag = '';
2516
  if ($nodes->length != 0) {
2517
+ foreach ($nodes as $k=>$v) {
2518
+ $node = $dom->getElementsByTagName('script')->item($k);
2519
+ if ($node->hasAttribute('src')) {
2520
+
2521
+ # bypass if there are linebreaks (will break document.write)
2522
+ if (stripos($ntag, PHP_EOL) !== false || stripos($tag, 'navigator.userAgent.match') !== false) {
2523
+ $newtag.= $dom->saveHTML($node);
2524
+ } else {
2525
+ $ntag = $dom->saveHTML($node);
2526
+ $newtag.= '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($ntag).');}</script>';
2527
+ }
2528
+
2529
+ } else {
2530
+ $newtag.= $dom->saveHTML($node);
2531
+ }
2532
+ }
2533
+
2534
+ # print code if there are no linebreaks, or return
2535
+ if(!empty($newtag)) {
2536
+ return $newtag;
2537
+ }
2538
  }
 
2539
  }
2540
 
2541
  # fallback
inc/functions.php CHANGED
@@ -105,16 +105,18 @@ if(function_exists('stat') && fvm_function_available('stat')) {
105
  # mkdir and check if umask requires chmod
106
  $dirs = array($cachebase, $cachedir, $tmpdir, $headerdir);
107
  foreach ($dirs as $target) {
108
- if (@mkdir($target, $dir_perms, true)){
109
- if ($dir_perms != ($dir_perms & ~umask())){
110
- $folder_parts = explode( '/', substr( $target, strlen(dirname($target)) + 1 ) );
111
- for ( $i = 1, $c = count( $folder_parts ); $i <= $c; $i++ ) {
112
- @chmod(dirname($target) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
 
 
113
  }
 
 
 
114
  }
115
- } else {
116
- # fallback
117
- if(!is_dir($target)) { wp_mkdir_p($target); }
118
  }
119
  }
120
 
@@ -143,7 +145,7 @@ function fastvelocity_plugin_activate() {
143
  update_option('fastvelocity_min_blacklist', implode(PHP_EOL, $exc));
144
 
145
  # default ignore list
146
- $exc = array('/Avada/assets/js/main.min.js', '/woocommerce-product-search/js/product-search.js', '/includes/builder/scripts/frontend-builder-scripts.js', '/assets/js/jquery.themepunch.tools.min.js', '/js/TweenMax.min.js', '/jupiter/assets/js/min/full-scripts', '/wp-content/themes/Divi/core/admin/js/react-dom.production.min.js');
147
  update_option('fastvelocity_min_ignorelist', implode(PHP_EOL, $exc));
148
 
149
  }
@@ -486,26 +488,6 @@ return $css;
486
  }
487
 
488
 
489
-
490
- # get remote urls with curl
491
- function fvm_file_get_contents_curl($url, $uagent=NULL) {
492
- $ch = curl_init();
493
- if(isset($uagent) && !empty($uagent)) { curl_setopt($ch,CURLOPT_USERAGENT, $uagent); }
494
- curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
495
- curl_setopt($ch, CURLOPT_HEADER, 0);
496
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
497
- curl_setopt($ch, CURLOPT_URL, $url);
498
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
499
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT , 10);
500
- curl_setopt($ch, CURLOPT_TIMEOUT, 15);
501
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
502
- $data = curl_exec($ch);
503
- curl_close($ch);
504
- return $data;
505
- }
506
-
507
-
508
-
509
  # download and cache css and js files
510
  function fvm_download_and_minify($hurl, $inline, $disable_minification, $type, $handle){
511
  global $cachedir, $cachedirurl, $wp_domain, $wp_home, $wp_home_path, $fvm_debug;
@@ -569,8 +551,11 @@ $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $
569
 
570
 
571
  # else, fallback to remote urls (or windows)
572
- $code = fastvelocity_download($hurl);
573
- if($code !== false) {
 
 
 
574
  if($type == 'js') {
575
  $code = fastvelocity_min_get_js($hurl, $code, $disable_minification);
576
  } else {
@@ -590,7 +575,7 @@ $printurl = str_ireplace(array(site_url(), home_url(), 'http:', 'https:'), '', $
590
  if(stripos($hurl, $wp_domain) !== false && home_url() != site_url()) {
591
  $nhurl = str_ireplace(site_url(), home_url(), $hurl);
592
  $code = fastvelocity_download($nhurl);
593
- if($code !== false) {
594
  if($type == 'js') {
595
  $code = fastvelocity_min_get_js($hurl, $code, $disable_minification);
596
  } else {
@@ -694,11 +679,11 @@ function fastvelocity_min_concatenate_google_fonts($array) {
694
  $multiple = explode('|', $font);
695
  if (count($multiple) > 0) {
696
  foreach ($multiple as $f) {
697
- $families[] = trim($f);
698
  }
699
  }
700
  } else {
701
- $families[] = $font;
702
  }
703
  }
704
  }
@@ -1045,14 +1030,6 @@ function fastvelocity_download($url) {
1045
  return false;
1046
  }
1047
 
1048
- # fallback, let's try curl if available
1049
- if(function_exists('curl_version')) {
1050
- $curl = fvm_file_get_contents_curl($url, $uagent);
1051
- if($curl !== false && !empty($curl) && strlen($curl) > 1) {
1052
- return $curl;
1053
- }
1054
- }
1055
-
1056
  # fallback fail
1057
  return false;
1058
  }
105
  # mkdir and check if umask requires chmod
106
  $dirs = array($cachebase, $cachedir, $tmpdir, $headerdir);
107
  foreach ($dirs as $target) {
108
+ if(!is_dir($target)) {
109
+ if (@mkdir($target, $dir_perms, true)){
110
+ if ($dir_perms != ($dir_perms & ~umask())){
111
+ $folder_parts = explode( '/', substr($target, strlen(dirname($target)) + 1 ));
112
+ for ($i = 1, $c = count($folder_parts ); $i <= $c; $i++){
113
+ @chmod(dirname($target) . '/' . implode( '/', array_slice( $folder_parts, 0, $i ) ), $dir_perms );
114
+ }
115
  }
116
+ } else {
117
+ # fallback
118
+ wp_mkdir_p($target);
119
  }
 
 
 
120
  }
121
  }
122
 
145
  update_option('fastvelocity_min_blacklist', implode(PHP_EOL, $exc));
146
 
147
  # default ignore list
148
+ $exc = array('/Avada/assets/js/main.min.js', '/woocommerce-product-search/js/product-search.js', '/includes/builder/scripts/frontend-builder-scripts.js', '/assets/js/jquery.themepunch.tools.min.js', '/js/TweenMax.min.js', '/jupiter/assets/js/min/full-scripts', '/wp-content/themes/Divi/core/admin/js/react-dom.production.min.js', '/LayerSlider/static/layerslider/js/greensock.js', '/themes/kalium/assets/js/main.min.js');
149
  update_option('fastvelocity_min_ignorelist', implode(PHP_EOL, $exc));
150
 
151
  }
488
  }
489
 
490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
491
  # download and cache css and js files
492
  function fvm_download_and_minify($hurl, $inline, $disable_minification, $type, $handle){
493
  global $cachedir, $cachedirurl, $wp_domain, $wp_home, $wp_home_path, $fvm_debug;
551
 
552
 
553
  # else, fallback to remote urls (or windows)
554
+ $code = fastvelocity_download($hurl);
555
+ if($code !== false && !empty($code) && strtolower(substr($code, 0, 9)) != "<!doctype") {
556
+
557
+ # check if we got HTML instead of js or css code
558
+
559
  if($type == 'js') {
560
  $code = fastvelocity_min_get_js($hurl, $code, $disable_minification);
561
  } else {
575
  if(stripos($hurl, $wp_domain) !== false && home_url() != site_url()) {
576
  $nhurl = str_ireplace(site_url(), home_url(), $hurl);
577
  $code = fastvelocity_download($nhurl);
578
+ if($code !== false && !empty($code) && strtolower(substr($code, 0, 9)) != "<!doctype") {
579
  if($type == 'js') {
580
  $code = fastvelocity_min_get_js($hurl, $code, $disable_minification);
581
  } else {
679
  $multiple = explode('|', $font);
680
  if (count($multiple) > 0) {
681
  foreach ($multiple as $f) {
682
+ $families[] = str_ireplace('subsets', 'subset', trim($f));
683
  }
684
  }
685
  } else {
686
+ $families[] = str_ireplace('subsets', 'subset', trim($font));
687
  }
688
  }
689
  }
1030
  return false;
1031
  }
1032
 
 
 
 
 
 
 
 
 
1033
  # fallback fail
1034
  return false;
1035
  }
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
- Stable tag: 2.5.1
6
- Tested up to: 5.0.2
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
@@ -116,7 +116,7 @@ Yes! Currently FVM recommends the "Cache Enabler" plugin, for it's simplicity, c
116
 
117
  = Is it resource intensive, or will it use too much CPU on my shared hosting plan? =
118
 
119
- Unless you are not excluding dynamic CSS files that change the url in every pageload, no it is not heavy at all. On the first run, each single file is minified into an intermediate cache. When a new group of CSS/JS files is found on a new page, it reuses those files and merges them into a new static cache file. All pages that request the same group of CSS or JS files will also make use of that file, thus regeneration only happens once ina while.
120
 
121
 
122
  = Is it compatible with multisites? =
@@ -124,14 +124,14 @@ Unless you are not excluding dynamic CSS files that change the url in every page
124
  Yes, it generates a new cache file for every different set of JS and CSS requirements it finds, but you must enable and configure FVM settings for each site in your network separatly (no global settings for all sites).
125
 
126
 
127
- = How do I use the pre-compressed files with gzip_static on Nginx? =
128
 
129
- When we merge and minify the css and js files, we also create a `.gz` file to be used with `gzip_static` on Nginx. You need to enable this feature on your Nginx configuration file if you want to make use of it.
130
 
131
 
132
  = Is it compatible with AdSense and other ad networks? =
133
 
134
- If you are just insertigng ads on your pages, yes. If you are using a custom script to inject those ads, please double check if it works.
135
 
136
 
137
  = After installing, why are some images and sliders not working? =
@@ -201,6 +201,13 @@ If you would like to donate any amount to the plugin author (thank you in advanc
201
 
202
  == Changelog ==
203
 
 
 
 
 
 
 
 
204
  = 2.5.1 [2018.12.17] =
205
  * minor bug fix related to the font awesome option
206
  * added cache purging support to Breeze (Cloudways)
2
  Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance, Optimization, Speed, Fast
4
  Requires at least: 4.5
5
+ Stable tag: 2.5.2
6
+ Tested up to: 5.0.3
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
9
 
116
 
117
  = Is it resource intensive, or will it use too much CPU on my shared hosting plan? =
118
 
119
+ Unless you are not excluding dynamic CSS files that change the url in every pageload, no it is not heavy at all. On the first run, each single file is minified into an intermediate cache. When a new group of CSS/JS files is found on a new page, it reuses those files and merges them into a new static cache file. All pages that request the same group of CSS or JS files will also make use of that file, thus regeneration only happens once.
120
 
121
 
122
  = Is it compatible with multisites? =
124
  Yes, it generates a new cache file for every different set of JS and CSS requirements it finds, but you must enable and configure FVM settings for each site in your network separatly (no global settings for all sites).
125
 
126
 
127
+ = How do I use the pre-compressed files with gzip_static or brotli_static on Nginx? =
128
 
129
+ When we merge and minify the css and js files, we also create a `.gz` file to be used with `gzip_static` on Nginx. You need to enable this feature on your Nginx configuration file if you want to make use of it. Likewise, if you have Nginx compiled with brotli and have enabled the php-ext-brotli extension for PHP, you can enable the brotli_static option and FVM will also generate .br files for you :)
130
 
131
 
132
  = Is it compatible with AdSense and other ad networks? =
133
 
134
+ If you are just inserting ads on your pages, yes. If you are using a custom script to inject those ads, please double check if it works.
135
 
136
 
137
  = After installing, why are some images and sliders not working? =
201
 
202
  == Changelog ==
203
 
204
+ = 2.5.2 [2019.01.11] =
205
+ * fixed a query monitor notice about mkdir
206
+ * removed some legacy code
207
+ * improvement for the "defer for pagespeed option", "ignore list" and "loadCSS" functionality
208
+ * improvements for the merging of google fonts option
209
+ * improvements for merging of JS and CSS files when server returns an HTML 404 page, but with HTTP 200 OK header instead
210
+
211
  = 2.5.1 [2018.12.17] =
212
  * minor bug fix related to the font awesome option
213
  * added cache purging support to Breeze (Cloudways)