Fast Velocity Minify - Version 2.3.4

Version Description

[2018.06.30] = * bug fix

Download this release

Release Info

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

Code changes from version 2.3.2 to 2.3.4

Files changed (4) hide show
  1. fvm.php +74 -47
  2. inc/functions-serverinfo.php +6 -6
  3. inc/functions.php +47 -22
  4. readme.txt +9 -7
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.3.2
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
@@ -111,7 +111,6 @@ $disable_css_minification = get_option('fastvelocity_min_disable_css_minificatio
111
  $use_yui = get_option('fastvelocity_min_use_yui');
112
  $remove_print_mediatypes = get_option('fastvelocity_min_remove_print_mediatypes');
113
  $skip_html_minification = get_option('fastvelocity_min_skip_html_minification');
114
- $use_alt_html_minification = get_option('fastvelocity_min_use_alt_html_minification');
115
  $strip_htmlcomments = get_option('fastvelocity_min_strip_htmlcomments');
116
  $skip_cssorder = get_option('fastvelocity_min_skip_cssorder');
117
  $skip_google_fonts = get_option('fastvelocity_min_skip_google_fonts');
@@ -179,7 +178,7 @@ if(is_admin()) {
179
  }
180
 
181
  # when css async is on
182
- add_action('wp_head', 'fvm_add_loadcss', PHP_INT_MAX);
183
 
184
 
185
  # remove query from static assets and process defering (if enabled)
@@ -303,7 +302,6 @@ function fastvelocity_min_register_settings() {
303
  register_setting('fvm-group', 'fastvelocity_min_use_yui');
304
  register_setting('fvm-group', 'fastvelocity_min_remove_print_mediatypes');
305
  register_setting('fvm-group', 'fastvelocity_min_skip_html_minification');
306
- register_setting('fvm-group', 'fastvelocity_min_use_alt_html_minification');
307
  register_setting('fvm-group', 'fastvelocity_min_strip_htmlcomments');
308
  register_setting('fvm-group', 'fastvelocity_min_skip_cssorder');
309
  register_setting('fvm-group', 'fastvelocity_min_skip_google_fonts');
@@ -322,6 +320,7 @@ function fastvelocity_min_register_settings() {
322
  register_setting('fvm-group', 'fastvelocity_min_preconnect');
323
  register_setting('fvm-group', 'fastvelocity_min_fvm_fix_editor');
324
  register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_url');
 
325
 
326
  # pro version (for private usage... or if you know what you're doing)
327
  register_setting('fvm-group-pro', 'fastvelocity_min_loadcss');
@@ -497,11 +496,6 @@ Disable HTML Minification <span class="note-info">[ This will disable HTML minif
497
  Strip HTML comments <span class="note-info">[ Only works with the default HTML minification, but note that some plugins need HTML comments to work properly ]</span></label>
498
  <br />
499
 
500
- <label for="fastvelocity_min_use_alt_html_minification">
501
- <input name="fastvelocity_min_use_alt_html_minification" type="checkbox" id="fastvelocity_min_use_alt_html_minification" value="1" <?php echo checked(1 == get_option('fastvelocity_min_use_alt_html_minification'), true, false); ?>>
502
- Use the alternative HTML minification <span class="note-info">[ Select this, ONLY if you have trouble with the default HTML minification ]</span></label>
503
- <br />
504
-
505
  </fieldset></td>
506
  </tr>
507
 
@@ -618,12 +612,12 @@ Enable defer parsing of JS files globally <span class="note-info">[ Not all brow
618
  <br />
619
  <label for="fastvelocity_min_defer_for_pagespeed">
620
  <input name="fastvelocity_min_defer_for_pagespeed" type="checkbox" id="fastvelocity_min_defer_for_pagespeed" value="1" <?php echo checked(1 == get_option('fastvelocity_min_defer_for_pagespeed'), true, false); ?>>
621
- Enable defer of JS for Pagespeed Insights <span class="note-info">[ Defer JS files for Pagespeed Insights only, <a target="_blank" href="https://www.chromestatus.com/feature/5718547946799104">except external scripts</a> (avoid using a CDN for JS files) ]</span></label>
622
  <br />
623
 
624
  <label for="fastvelocity_min_defer_for_pagespeed_optimize">
625
  <input name="fastvelocity_min_defer_for_pagespeed_optimize" type="checkbox" id="fastvelocity_min_defer_for_pagespeed_optimize" value="1" <?php echo checked(1 == get_option('fastvelocity_min_defer_for_pagespeed_optimize'), true, false); ?>>
626
- Also defer the "ignore list" for Pagespeed Insights <span class="note-info">[ Defer JS files on the ignore list for Pagespeed Insights only ]</span></label>
627
  <br />
628
 
629
  <label for="fastvelocity_min_exclude_defer_jquery">
@@ -663,17 +657,26 @@ Skip deferring completely on the login page <span class="note-info">[ If selecte
663
 
664
  <div style="height: 20px;"></div>
665
  <h2 class="title">CDN Options</h2>
666
- <p class="fvm-bold-green">If the "Enable defer of JS for Pagespeed Insights" option is enabled, JS and CSS files will not be loaded from the CDN.<br />However, the static assets used inside the CSS and JS files will load from the CDN directly.</p>
667
 
668
  <table class="form-table fvm-settings">
669
  <tbody>
670
  <tr>
671
  <th scope="row"><span class="fvm-label-special">Your CDN domain</span></th>
672
  <td><fieldset>
 
673
  <label for="fastvelocity_min_fvm_cdn_url">
674
  <p><input type="text" name="fastvelocity_min_fvm_cdn_url" id="fastvelocity_min_fvm_cdn_url" value="<?php echo get_option('fastvelocity_min_fvm_cdn_url', ''); ?>" size="80" /></p>
675
- <p class="description">[ Load the generated CSS and JS urls (only) from your cdn domain name, ie: cdn.example.com ]</p></label>
676
- </fieldset></td>
 
 
 
 
 
 
 
 
677
  </tr>
678
  </tbody></table>
679
 
@@ -1026,12 +1029,16 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1026
  }
1027
  if(count($data) > 0) { $wp_scripts->registered["fvm-header-$i"]->extra['data'] = implode("\n", $data); }
1028
 
1029
- # enqueue file
1030
- wp_enqueue_script("fvm-header-$i");
 
 
 
1031
 
1032
  # other scripts need to be requeued for the order of files to be kept
1033
  } else {
1034
- wp_dequeue_script($header[$i]['handle']); wp_enqueue_script($header[$i]['handle']);
 
1035
  }
1036
  }
1037
 
@@ -1136,7 +1143,8 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1136
 
1137
  # consider dependencies on handles with an empty src
1138
  } else {
1139
- wp_dequeue_script($handle); wp_enqueue_script($handle);
 
1140
  }
1141
  endforeach;
1142
 
@@ -1159,8 +1167,11 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1159
  }
1160
  if(count($data) > 0) { $wp_scripts->registered["fvm-footer-$i"]->extra['data'] = implode("\n", $data); }
1161
 
1162
- # enqueue file
1163
- wp_enqueue_script("fvm-footer-$i");
 
 
 
1164
 
1165
  # other scripts need to be requeued for the order of files to be kept
1166
  } else {
@@ -1222,7 +1233,7 @@ if($enable_defer_js == true) { return $tagdefer; }
1222
  if ($defer_for_pagespeed != true) { return $tag; } else {
1223
 
1224
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1225
- if (fvm_is_local_domain($src) == true) { return $tag; }
1226
 
1227
  # return if there are linebreaks (will break document.write)
1228
  if (stripos($tag, "\n") !== false) { return $tag; }
@@ -1470,7 +1481,8 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1470
 
1471
  # consider dependencies on handles with an empty src
1472
  } else {
1473
- wp_dequeue_script($handle); wp_enqueue_script($handle);
 
1474
  }
1475
  endforeach;
1476
 
@@ -1487,40 +1499,48 @@ for($i=0,$l=count($header);$i<$l;$i++) {
1487
  # register and enqueue minified file, consider excluding of mediatype "print" and inline css
1488
  if ($remove_print_mediatypes != 1 || ($remove_print_mediatypes == 1 && $header[$i]['media'] != 'print')) {
1489
  if($force_inline_css != false) {
1490
- echo '<style type="text/css" media="'.$header[$i]['media'].'">'.file_get_contents($file).'</style>';
 
 
 
 
 
 
1491
  } else {
1492
 
1493
  # move CSS to footer with loadCSS ?
1494
  if($loadcss != false) {
1495
  if($fvm_remove_css != true) {
1496
 
1497
- # save to some sort of global and show it on the footer
1498
- $mt = $header[$i]['media'];
1499
- echo '<link rel="preload" href="'.$file_url.'" as="style" media="'.$mt.'" onload="this.onload=null;this.rel=\'stylesheet\'">';
1500
- echo '<noscript><link rel="stylesheet" type="text/css" media="'.$mt.'" href="'.$file_url.'"></noscript>';
1501
- echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="'.$mt.'" href="'.$file_url.'"><![endif]-->';
1502
 
1503
- /*
1504
- # alternative way
1505
- echo <<<EOF
1506
- <script type="text/javascript">var ldfvm$i=document.createElement("link");ldfvm$i.rel="stylesheet",ldfvm$i.type="text/css",ldfvm$i.media="bogus",ldfvm$i.href="$file_url",ldfvm$i.onload=function(){ldfvm$i.media="$mt"},document.getElementsByTagName("head")[0].appendChild(ldfvm$i);</script>
1507
- EOF;
1508
- */
1509
 
1510
  }
1511
  } else {
1512
-
1513
- # default
1514
- wp_register_style("fvm-header-$i", $file_url, array(), null, $header[$i]['media']);
1515
- wp_enqueue_style("fvm-header-$i");
1516
-
 
1517
  }
1518
  }
1519
  }
1520
 
1521
  # other css need to be requeued for the order of files to be kept
1522
  } else {
1523
- wp_dequeue_style($header[$i]['handle']); wp_enqueue_style($header[$i]['handle']);
 
1524
  }
1525
  }
1526
 
@@ -1594,7 +1614,7 @@ if(!$skip_google_fonts && count($google_fonts) > 0) {
1594
 
1595
  # inline css or fail
1596
  if($newcode !== false) {
1597
- echo '<style type="text/css" media="all">'.$newcode.'</style>';
1598
  } else {
1599
  echo "<!-- GOOGLE FONTS REQUEST FAILED for $concat_google_fonts -->\n"; # log if failed
1600
  }
@@ -1731,7 +1751,8 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1731
 
1732
  # consider dependencies on handles with an empty src
1733
  } else {
1734
- wp_dequeue_script($handle); wp_enqueue_script($handle);
 
1735
  }
1736
  endforeach;
1737
 
@@ -1757,15 +1778,20 @@ for($i=0,$l=count($footer);$i<$l;$i++) {
1757
  echo '<link rel="stylesheet" type="text/css" media="'.$footer[$i]['media'].'" href="'.$file_url.'">';
1758
  }
1759
  } else {
1760
- wp_register_style("fvm-footer-$i", $file_url, array(), null, $footer[$i]['media']);
1761
- wp_enqueue_style("fvm-footer-$i");
 
 
 
 
1762
  }
1763
  }
1764
  }
1765
 
1766
  # other css need to be requeued for the order of files to be kept
1767
  } else {
1768
- wp_dequeue_style($footer[$i]['handle']); wp_enqueue_style($footer[$i]['handle']);
 
1769
  }
1770
  }
1771
 
@@ -1778,6 +1804,7 @@ $wp_styles->done = $done;
1778
 
1779
  ###########################################
1780
  # defer CSS globally from the header (order matters)
 
1781
  ###########################################
1782
  function fvm_add_loadcss() {
1783
  global $force_inline_css, $loadcss, $fvm_remove_css;
@@ -1786,7 +1813,7 @@ if($force_inline_css == true && $loadcss != false && $fvm_remove_css != true) {
1786
  # echo LoadCSS scripts
1787
  echo '<script>
1788
  /*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
1789
- !function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);
1790
  </script>';
1791
  }
1792
  }
@@ -1842,7 +1869,7 @@ if (stripos($tag, "\n") !== false) { return $tag; }
1842
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
1843
 
1844
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1845
- if (fvm_is_local_domain($src) == true) { return $tag; }
1846
 
1847
  # exclude ignored scripts
1848
  if(substr($handle, 0, 4) != "fvm-" && $defer_for_pagespeed == true && $defer_for_pagespeed_optimize == true) {
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.3.4
9
  License: GPL2
10
 
11
  ------------------------------------------------------------------------
111
  $use_yui = get_option('fastvelocity_min_use_yui');
112
  $remove_print_mediatypes = get_option('fastvelocity_min_remove_print_mediatypes');
113
  $skip_html_minification = get_option('fastvelocity_min_skip_html_minification');
 
114
  $strip_htmlcomments = get_option('fastvelocity_min_strip_htmlcomments');
115
  $skip_cssorder = get_option('fastvelocity_min_skip_cssorder');
116
  $skip_google_fonts = get_option('fastvelocity_min_skip_google_fonts');
178
  }
179
 
180
  # when css async is on
181
+ add_action('wp_footer', 'fvm_add_loadcss', PHP_INT_MAX);
182
 
183
 
184
  # remove query from static assets and process defering (if enabled)
302
  register_setting('fvm-group', 'fastvelocity_min_use_yui');
303
  register_setting('fvm-group', 'fastvelocity_min_remove_print_mediatypes');
304
  register_setting('fvm-group', 'fastvelocity_min_skip_html_minification');
 
305
  register_setting('fvm-group', 'fastvelocity_min_strip_htmlcomments');
306
  register_setting('fvm-group', 'fastvelocity_min_skip_cssorder');
307
  register_setting('fvm-group', 'fastvelocity_min_skip_google_fonts');
320
  register_setting('fvm-group', 'fastvelocity_min_preconnect');
321
  register_setting('fvm-group', 'fastvelocity_min_fvm_fix_editor');
322
  register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_url');
323
+ register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_force');
324
 
325
  # pro version (for private usage... or if you know what you're doing)
326
  register_setting('fvm-group-pro', 'fastvelocity_min_loadcss');
496
  Strip HTML comments <span class="note-info">[ Only works with the default HTML minification, but note that some plugins need HTML comments to work properly ]</span></label>
497
  <br />
498
 
 
 
 
 
 
499
  </fieldset></td>
500
  </tr>
501
 
612
  <br />
613
  <label for="fastvelocity_min_defer_for_pagespeed">
614
  <input name="fastvelocity_min_defer_for_pagespeed" type="checkbox" id="fastvelocity_min_defer_for_pagespeed" value="1" <?php echo checked(1 == get_option('fastvelocity_min_defer_for_pagespeed'), true, false); ?>>
615
+ Enable defer of JS for Pagespeed Insights <span class="note-info">[ Defer JS files for Pagespeed Insights only ]</span></label>
616
  <br />
617
 
618
  <label for="fastvelocity_min_defer_for_pagespeed_optimize">
619
  <input name="fastvelocity_min_defer_for_pagespeed_optimize" type="checkbox" id="fastvelocity_min_defer_for_pagespeed_optimize" value="1" <?php echo checked(1 == get_option('fastvelocity_min_defer_for_pagespeed_optimize'), true, false); ?>>
620
+ Exclude JS files in the "ignore list" from Pagespeed Insights <span class="note-info">[ This only works with the option to defer for Pagespeed Insights ]</span></label>
621
  <br />
622
 
623
  <label for="fastvelocity_min_exclude_defer_jquery">
657
 
658
  <div style="height: 20px;"></div>
659
  <h2 class="title">CDN Options</h2>
660
+ <p class="fvm-bold-green">When the "Enable defer of JS for Pagespeed Insights" option is enabled, JS and CSS files will not be loaded from the CDN due to <a target="_blank" href="https://www.chromestatus.com/feature/5718547946799104">compatibility</a> reasons.<br />However, you can define a CDN Domain below, in order to use it for all of the static assets "inside" your CSS and JS files.</p>
661
 
662
  <table class="form-table fvm-settings">
663
  <tbody>
664
  <tr>
665
  <th scope="row"><span class="fvm-label-special">Your CDN domain</span></th>
666
  <td><fieldset>
667
+
668
  <label for="fastvelocity_min_fvm_cdn_url">
669
  <p><input type="text" name="fastvelocity_min_fvm_cdn_url" id="fastvelocity_min_fvm_cdn_url" value="<?php echo get_option('fastvelocity_min_fvm_cdn_url', ''); ?>" size="80" /></p>
670
+ <p class="description">[ Will rewrite the static assets urls inside FVM merged files to your cdn domain. Usage: cdn.example.com ]</p></label>
671
+ </fieldset>
672
+ <br />
673
+
674
+ <label for="fastvelocity_min_fvm_cdn_force">
675
+ <input name="fastvelocity_min_fvm_cdn_force" type="checkbox" id="fastvelocity_min_fvm_cdn_force" value="1" <?php echo checked(1 == get_option('fastvelocity_min_fvm_cdn_force'), true, false); ?>>
676
+ I know what I'm doing... <span class="note-info">[ Load my JS files from the CDN, even when "defer for Pagespeed Insights" is enabled ]</span></label>
677
+ <br />
678
+
679
+ </td>
680
  </tr>
681
  </tbody></table>
682
 
1029
  }
1030
  if(count($data) > 0) { $wp_scripts->registered["fvm-header-$i"]->extra['data'] = implode("\n", $data); }
1031
 
1032
+ # enqueue file, if not empty
1033
+ $check = ''; $check = trim(file_get_contents($file));
1034
+ if(file_exists($file) && (!empty($check) || count($data) > 0)) {
1035
+ wp_enqueue_script("fvm-header-$i");
1036
+ }
1037
 
1038
  # other scripts need to be requeued for the order of files to be kept
1039
  } else {
1040
+ wp_dequeue_script($header[$i]['handle']);
1041
+ wp_enqueue_script($header[$i]['handle']);
1042
  }
1043
  }
1044
 
1143
 
1144
  # consider dependencies on handles with an empty src
1145
  } else {
1146
+ wp_dequeue_script($handle);
1147
+ wp_enqueue_script($handle);
1148
  }
1149
  endforeach;
1150
 
1167
  }
1168
  if(count($data) > 0) { $wp_scripts->registered["fvm-footer-$i"]->extra['data'] = implode("\n", $data); }
1169
 
1170
+ # enqueue file, if not empty
1171
+ $check = ''; $check = trim(file_get_contents($file));
1172
+ if(file_exists($file) && (!empty($check) || count($data) > 0)) {
1173
+ wp_enqueue_script("fvm-footer-$i");
1174
+ }
1175
 
1176
  # other scripts need to be requeued for the order of files to be kept
1177
  } else {
1233
  if ($defer_for_pagespeed != true) { return $tag; } else {
1234
 
1235
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1236
+ if (fvm_is_local_domain($src) !== true) { return $tag; }
1237
 
1238
  # return if there are linebreaks (will break document.write)
1239
  if (stripos($tag, "\n") !== false) { return $tag; }
1481
 
1482
  # consider dependencies on handles with an empty src
1483
  } else {
1484
+ wp_dequeue_script($handle);
1485
+ wp_enqueue_script($handle);
1486
  }
1487
  endforeach;
1488
 
1499
  # register and enqueue minified file, consider excluding of mediatype "print" and inline css
1500
  if ($remove_print_mediatypes != 1 || ($remove_print_mediatypes == 1 && $header[$i]['media'] != 'print')) {
1501
  if($force_inline_css != false) {
1502
+
1503
+ # print file, if not empty
1504
+ $check = ''; $check = trim(file_get_contents($file));
1505
+ if(file_exists($file) && !empty($check)) {
1506
+ echo '<style type="text/css" media="'.$header[$i]['media'].'">'.$check.'</style>';
1507
+ }
1508
+
1509
  } else {
1510
 
1511
  # move CSS to footer with loadCSS ?
1512
  if($loadcss != false) {
1513
  if($fvm_remove_css != true) {
1514
 
1515
+ # save to some sort of global and show it on the footer
1516
+ $mt = $header[$i]['media'];
1517
+ echo '<link rel="preload" href="'.$file_url.'" as="style" media="'.$mt.'" onload="this.onload=null;this.rel=\'stylesheet\'">';
1518
+ echo '<noscript><link rel="stylesheet" type="text/css" media="'.$mt.'" href="'.$file_url.'"></noscript>';
1519
+ echo '<!--[if IE]><link rel="stylesheet" type="text/css" media="'.$mt.'" href="'.$file_url.'"><![endif]-->';
1520
 
1521
+ /*
1522
+ # alternative way
1523
+ echo <<<EOF
1524
+ <script type="text/javascript">var ldfvm$i=document.createElement("link");ldfvm$i.rel="stylesheet",ldfvm$i.type="text/css",ldfvm$i.media="bogus",ldfvm$i.href="$file_url",ldfvm$i.onload=function(){ldfvm$i.media="$mt"},document.getElementsByTagName("head")[0].appendChild(ldfvm$i);</script>
1525
+ EOF;
1526
+ */
1527
 
1528
  }
1529
  } else {
1530
+ # enqueue file, if not empty
1531
+ $check = ''; $check = trim(file_get_contents($file));
1532
+ if(file_exists($file) && !empty($check)) {
1533
+ wp_register_style("fvm-header-$i", $file_url, array(), null, $header[$i]['media']);
1534
+ wp_enqueue_style("fvm-header-$i");
1535
+ }
1536
  }
1537
  }
1538
  }
1539
 
1540
  # other css need to be requeued for the order of files to be kept
1541
  } else {
1542
+ wp_dequeue_style($header[$i]['handle']);
1543
+ wp_enqueue_style($header[$i]['handle']);
1544
  }
1545
  }
1546
 
1614
 
1615
  # inline css or fail
1616
  if($newcode !== false) {
1617
+ echo '<style type="text/css" media="all">'.$newcode.'</style>';
1618
  } else {
1619
  echo "<!-- GOOGLE FONTS REQUEST FAILED for $concat_google_fonts -->\n"; # log if failed
1620
  }
1751
 
1752
  # consider dependencies on handles with an empty src
1753
  } else {
1754
+ wp_dequeue_script($handle);
1755
+ wp_enqueue_script($handle);
1756
  }
1757
  endforeach;
1758
 
1778
  echo '<link rel="stylesheet" type="text/css" media="'.$footer[$i]['media'].'" href="'.$file_url.'">';
1779
  }
1780
  } else {
1781
+ # enqueue file, if not empty
1782
+ $check = ''; $check = trim(file_get_contents($file));
1783
+ if(file_exists($file) && !empty($check)) {
1784
+ wp_register_style("fvm-footer-$i", $file_url, array(), null, $footer[$i]['media']);
1785
+ wp_enqueue_style("fvm-footer-$i");
1786
+ }
1787
  }
1788
  }
1789
  }
1790
 
1791
  # other css need to be requeued for the order of files to be kept
1792
  } else {
1793
+ wp_dequeue_style($footer[$i]['handle']);
1794
+ wp_enqueue_style($footer[$i]['handle']);
1795
  }
1796
  }
1797
 
1804
 
1805
  ###########################################
1806
  # defer CSS globally from the header (order matters)
1807
+ # dev: https://www.filamentgroup.com/lab/async-css.html
1808
  ###########################################
1809
  function fvm_add_loadcss() {
1810
  global $force_inline_css, $loadcss, $fvm_remove_css;
1813
  # echo LoadCSS scripts
1814
  echo '<script>
1815
  /*! loadCSS rel=preload polyfill. [c]2017 Filament Group, Inc. MIT License */
1816
+ !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);
1817
  </script>';
1818
  }
1819
  }
1869
  if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
1870
 
1871
  # return if external script url https://www.chromestatus.com/feature/5718547946799104
1872
+ if (fvm_is_local_domain($src) !== true) { return $tag; }
1873
 
1874
  # exclude ignored scripts
1875
  if(substr($handle, 0, 4) != "fvm-" && $defer_for_pagespeed == true && $defer_for_pagespeed_optimize == true) {
inc/functions-serverinfo.php CHANGED
@@ -120,10 +120,10 @@ if(!function_exists('fvm_format_filesize')) {
120
  } elseif($rawSize > 1) {
121
  return number_format_i18n($rawSize, 0).' '.__('bytes', 'fvm-serverinfo');
122
  } else {
123
- return __('unknown', 'fvm-serverinfo');
124
  }
125
  } else {
126
- return __('unknown', 'fvm-serverinfo');
127
  }
128
  }
129
  }
@@ -233,7 +233,7 @@ if(!function_exists('fvm_get_mysql_version')) {
233
  if(!function_exists('fvm_get_mysql_data_usage')) {
234
  function fvm_get_mysql_data_usage() {
235
  global $wpdb;
236
- $data_usage = '';
237
  $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
238
  foreach($tablesstatus as $tablestatus) {
239
  if(is_numeric($tablestatus->Data_length)) { $data_usage += $tablestatus->Data_length; } else { $data_usage += 0; }
@@ -250,7 +250,7 @@ if(!function_exists('fvm_get_mysql_data_usage')) {
250
  if(!function_exists('fvm_get_mysql_index_usage')) {
251
  function fvm_get_mysql_index_usage() {
252
  global $wpdb;
253
- $index_usage = '';
254
  $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
255
  foreach($tablesstatus as $tablestatus) {
256
  if(is_numeric($tablestatus->Index_length)) { $index_usage += $tablestatus->Index_length; } else { $index_usage += 0; }
@@ -307,7 +307,7 @@ if(!function_exists('fvm_get_mysql_query_cache_size')) {
307
  ### Function: Get The Server Load
308
  if(!function_exists('fvm_get_serverload')) {
309
  function fvm_get_serverload() {
310
- $server_load = '';
311
  $numCpus = 'N/A';
312
  if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
313
  clearstatcache();
@@ -347,7 +347,7 @@ if(!function_exists('fvm_get_serverload')) {
347
  ### Function: Get The Server CPU's
348
  if(!function_exists('fvm_get_servercpu')) {
349
  function fvm_get_servercpu() {
350
- $numCpus = '';
351
  if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
352
  clearstatcache();
353
  if (is_file('/proc/cpuinfo')) {
120
  } elseif($rawSize > 1) {
121
  return number_format_i18n($rawSize, 0).' '.__('bytes', 'fvm-serverinfo');
122
  } else {
123
+ return __('N/A', 'fvm-serverinfo');
124
  }
125
  } else {
126
+ return __('N/A', 'fvm-serverinfo');
127
  }
128
  }
129
  }
233
  if(!function_exists('fvm_get_mysql_data_usage')) {
234
  function fvm_get_mysql_data_usage() {
235
  global $wpdb;
236
+ $data_usage = 0;
237
  $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
238
  foreach($tablesstatus as $tablestatus) {
239
  if(is_numeric($tablestatus->Data_length)) { $data_usage += $tablestatus->Data_length; } else { $data_usage += 0; }
250
  if(!function_exists('fvm_get_mysql_index_usage')) {
251
  function fvm_get_mysql_index_usage() {
252
  global $wpdb;
253
+ $index_usage = 0;
254
  $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
255
  foreach($tablesstatus as $tablestatus) {
256
  if(is_numeric($tablestatus->Index_length)) { $index_usage += $tablestatus->Index_length; } else { $index_usage += 0; }
307
  ### Function: Get The Server Load
308
  if(!function_exists('fvm_get_serverload')) {
309
  function fvm_get_serverload() {
310
+ $server_load = 0;
311
  $numCpus = 'N/A';
312
  if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
313
  clearstatcache();
347
  ### Function: Get The Server CPU's
348
  if(!function_exists('fvm_get_servercpu')) {
349
  function fvm_get_servercpu() {
350
+ $numCpus = 0;
351
  if(PHP_OS != 'WINNT' && PHP_OS != 'WIN32') {
352
  clearstatcache();
353
  if (is_file('/proc/cpuinfo')) {
inc/functions.php CHANGED
@@ -54,11 +54,33 @@ return array('cachebase'=>$cachebase,'tmpdir'=>$tmpdir, 'cachedir'=>$cachedir, '
54
  # detect external or internal scripts
55
  function fvm_is_local_domain($src) {
56
  $locations = array(home_url(), site_url(), network_home_url(), network_site_url());
57
- foreach ($locations as $l) {
58
- $l = trim(trim(str_ireplace(array('http://', 'https://', 'www.', 'cdn.', 'static.', 'assets.'), '', trim($l)), '/'));
59
- if (stripos($src, $l) === false) { return true; }
60
- }
61
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
 
@@ -255,18 +277,8 @@ return fastvelocity_min_Minify_HTML::minify($html);
255
  # functions to minify HTML
256
  function fastvelocity_min_html_compression_finish($html) { return fastvelocity_min_minify_html($html); }
257
  function fastvelocity_min_html_compression_start() {
258
- if (fastvelocity_exclude_contents() == true) { return; }
259
- $use_alt_html_minification = get_option('fastvelocity_min_use_alt_html_minification', '0');
260
- if($use_alt_html_minification == '1') { ob_start('fastvelocity_min_minify_alt_html'); }
261
- else { ob_start('fastvelocity_min_html_compression_finish'); }
262
- }
263
-
264
- # alternative html minification, minimal
265
- function fastvelocity_min_minify_alt_html($html) {
266
- $html = trim(preg_replace('/\v(?:[\t\v\h]+)/iu', "\n", $html));
267
- $html = trim(preg_replace('/\t(?:[\t\v\h]+)/iu', ' ', $html));
268
- $html = trim(preg_replace('/\h(?:[\t\v\h]+)/iu', ' ', $html));
269
- return $html;
270
  }
271
 
272
 
@@ -645,12 +657,24 @@ function fvm_get_protocol($url) {
645
 
646
  # cdn support
647
  $fvm_cdn_url = get_option('fastvelocity_min_fvm_cdn_url');
648
- $defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
649
 
650
- # excluded from cdn because of https://www.chromestatus.com/feature/5718547946799104 (we use document.write to preserve render blocking)
651
- if(!empty($fvm_cdn_url) && $defer_for_pagespeed != true) {
652
- $fvm_cdn_url = trim(trim(str_ireplace(array('http://', 'https://'), '', trim($fvm_cdn_url, '/'))), '/');
653
- $url = str_ireplace($wp_domain, $fvm_cdn_url, $url);
 
 
 
 
 
 
 
 
 
 
 
 
654
  }
655
 
656
  # enforce protocol if needed
@@ -695,6 +719,7 @@ function fvm_purge_all() {
695
  # remove cache files, set last update and clean legacy transients
696
  fastvelocity_rrmdir($cachebase);
697
  fvm_transients_purge();
 
698
  return true;
699
  }
700
 
54
  # detect external or internal scripts
55
  function fvm_is_local_domain($src) {
56
  $locations = array(home_url(), site_url(), network_home_url(), network_site_url());
57
+
58
+ # cdn support
59
+ $fvm_cdn_url = get_option('fastvelocity_min_fvm_cdn_url');
60
+ $defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
61
+ $fvm_cdn_force = get_option('fastvelocity_min_fvm_cdn_force');
62
+
63
+ # excluded from cdn because of https://www.chromestatus.com/feature/5718547946799104 (we use document.write to preserve render blocking)
64
+ if(!empty($fvm_cdn_url) && ($defer_for_pagespeed != true || $fvm_cdn_force != false) ) {
65
+ array_push($locations, $fvm_cdn_url);
66
+ }
67
+
68
+ # cleanup locations
69
+ $locations = array_filter(array_unique($locations));
70
+
71
+ # debug
72
+ $debug = array('src'=>$src, 'fvm_cdn_url'=>$fvm_cdn_url, 'defer_for_pagespeed'=>$defer_for_pagespeed, 'fvm_cdn_force'=>$fvm_cdn_force, 'locations'=>$locations);
73
+
74
+
75
+ # external or not?
76
+ $ret = false;
77
+ foreach ($locations as $l) {
78
+ $l = trim(trim(str_ireplace(array('http://', 'https://', 'www.'), '', trim($l)), '/'));
79
+ if (stripos($src, $l) !== false && $ret === false) { $ret = true; }
80
+ }
81
+
82
+ # response
83
+ return $ret;
84
  }
85
 
86
 
277
  # functions to minify HTML
278
  function fastvelocity_min_html_compression_finish($html) { return fastvelocity_min_minify_html($html); }
279
  function fastvelocity_min_html_compression_start() {
280
+ if (fastvelocity_exclude_contents() == true) { return; }
281
+ ob_start('fastvelocity_min_html_compression_finish');
 
 
 
 
 
 
 
 
 
 
282
  }
283
 
284
 
657
 
658
  # cdn support
659
  $fvm_cdn_url = get_option('fastvelocity_min_fvm_cdn_url');
660
+ $fvm_cdn_url = trim(trim(str_ireplace(array('http://', 'https://'), '', trim($fvm_cdn_url, '/'))), '/');
661
 
662
+ # process cdn rewrite
663
+ if(!empty($fvm_cdn_url) && fvm_is_local_domain($url) !== false) {
664
+
665
+ # for js files, we need to consider thew defer for insights option
666
+ if(substr($url, -3) == '.js') {
667
+
668
+ $defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
669
+ $fvm_cdn_force = get_option('fastvelocity_min_fvm_cdn_force');
670
+
671
+ if($defer_for_pagespeed != true || $fvm_cdn_force != false) {
672
+ $url = str_ireplace($wp_domain, $fvm_cdn_url, $url);
673
+ }
674
+
675
+ } else {
676
+ $url = str_ireplace($wp_domain, $fvm_cdn_url, $url);
677
+ }
678
  }
679
 
680
  # enforce protocol if needed
719
  # remove cache files, set last update and clean legacy transients
720
  fastvelocity_rrmdir($cachebase);
721
  fvm_transients_purge();
722
+ do_action('fvm_after_purge_all');
723
  return true;
724
  }
725
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Contributors: Alignak
3
  Tags: PHP Minify, YUI Compressor, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance
4
  Requires at least: 4.5
5
- Stable tag: 2.3.2
6
  Tested up to: 4.9.6
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -262,14 +262,16 @@ If you would like to donate any amount to the plugin author (thank you in advanc
262
 
263
  ...
264
 
 
265
 
266
- == Upgrade Notice ==
267
-
268
- = 2.2.4 =
269
- Note: Kindly re-save all options and purge all caches (the plugin cache as well as your server /plugin cache).
270
-
271
 
272
- == Changelog ==
 
 
 
 
273
 
274
  = 2.3.2 [2018.06.03] =
275
  * added some compatibility fixes when merging and minifying JS files
2
  Contributors: Alignak
3
  Tags: PHP Minify, YUI Compressor, GTmetrix, Pingdom, Pagespeed, CSS Merging, JS Merging, CSS Minification, JS Minification, Speed Optimization, HTML Minification, Performance
4
  Requires at least: 4.5
5
+ Stable tag: 2.3.4
6
  Tested up to: 4.9.6
7
  License: GPLv3 or later
8
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
262
 
263
  ...
264
 
265
+ == Changelog ==
266
 
267
+ = 2.3.4 [2018.06.30] =
268
+ * bug fix
 
 
 
269
 
270
+ = 2.3.3 [2018.06.30] =
271
+ * added a check to prevent creating an empty js or css file
272
+ * added an option to force the CDN option when using the defer for insights option
273
+ * removed the alternative HTML minification method
274
+ * minor performance and bug fixes
275
 
276
  = 2.3.2 [2018.06.03] =
277
  * added some compatibility fixes when merging and minifying JS files