Fast Velocity Minify - Version 3.0.4

Version Description

[2020.12.31] = * Improved compatibility on CSS merging with optimole and similar services * Fixed some PHP notices and other minor issues

Download this release

Release Info

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

Code changes from version 3.0.3 to 3.0.4

Files changed (5) hide show
  1. fvm.php +1 -1
  2. inc/common.php +33 -15
  3. inc/frontend.php +30 -23
  4. layout/admin-layout-settings.php +2 -2
  5. readme.txt +5 -1
fvm.php CHANGED
@@ -6,7 +6,7 @@ Description: Improve your speed score on GTmetrix, Pingdom Tools and Google Page
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
  Text Domain: fast-velocity-minify
9
- Version: 3.0.3
10
  License: GPL2
11
 
12
  ------------------------------------------------------------------------
6
  Author: Raul Peixoto
7
  Author URI: http://fastvelocity.com
8
  Text Domain: fast-velocity-minify
9
+ Version: 3.0.4
10
  License: GPL2
11
 
12
  ------------------------------------------------------------------------
inc/common.php CHANGED
@@ -787,11 +787,22 @@ function fvm_maybe_download($url) {
787
  # this useragent is needed for google fonts (woff files only + hinted fonts)
788
  $uagent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
789
 
790
- # cache buster
791
- $query = 'cache='.time();
792
  $parsedUrl = parse_url($url);
793
- if ($parsedUrl['path'] === null) { $url .= '/'; }
794
- if ($parsedUrl['query'] === null) { $separator = '?'; } else { $separator = '&'; }
 
 
 
 
 
 
 
 
 
 
 
 
795
  $url .= $separator.$query;
796
 
797
  # fetch via wordpress functions
@@ -1047,6 +1058,8 @@ function fvm_maybe_minify_css_file($css, $url, $min) {
1047
  foreach($matches[1] as $a) { $b = trim($a); if($b != $a) { $css = str_replace($a, $b, $css); } }
1048
  $css = preg_replace("/url\(\s*['\"]?(?!data:)(?!http)(?![\/'\"#])(.+?)['\"]?\s*\)/ui", "url(".dirname($url)."/$1)", $css);
1049
  }
 
 
1050
 
1051
  # minify string with relative urls
1052
  if($min) {
@@ -1057,6 +1070,22 @@ function fvm_maybe_minify_css_file($css, $url, $min) {
1057
  # https://developers.google.com/web/updates/2016/02/font-display
1058
  $css = str_ireplace('font-family:', 'font-display:block;font-family:', $css);
1059
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1060
  # return css
1061
  return trim($css);
1062
 
@@ -1112,21 +1141,10 @@ function fvm_minify_css_string($css) {
1112
  # return early if empty
1113
  if(empty($css) || $css == false) { return $css; }
1114
 
1115
- # get domain
1116
- global $fvm_urls;
1117
-
1118
  # minify
1119
  $minifier = new FVM\MatthiasMullie\Minify\CSS($css);
1120
  $minifier->setMaxImportSize(10); # embed assets up to 10 Kb (default 5Kb) - processes gif, png, jpg, jpeg, svg & woff
1121
  $min = $minifier->minify();
1122
-
1123
- # make relative urls
1124
- $min = str_replace('http://'.$fvm_urls['wp_domain'], '', $min);
1125
- $min = str_replace('https://'.$fvm_urls['wp_domain'], '', $min);
1126
- $min = str_replace('//'.$fvm_urls['wp_domain'], '', $min);
1127
- $min = str_replace('http://'.str_ireplace('www.', '', $fvm_urls['wp_domain']), '', $min);
1128
- $min = str_replace('https://'.str_ireplace('www.', '', $fvm_urls['wp_domain']), '', $min);
1129
- $min = str_replace('//'.str_ireplace('www.', '', $fvm_urls['wp_domain']), '', $min);
1130
 
1131
  # return
1132
  if($min != false) {
787
  # this useragent is needed for google fonts (woff files only + hinted fonts)
788
  $uagent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
789
 
790
+ # parse uri path
 
791
  $parsedUrl = parse_url($url);
792
+ if (!isset($parsedUrl['path']) || (isset($parsedUrl['path']) && $parsedUrl['path'] === null)) {
793
+ $url .= '/';
794
+ }
795
+
796
+ # cache buster
797
+ $query = 'nocache='.time();
798
+ $separator = '&';
799
+ if (isset($parsedUrl['query'])) {
800
+ if ($parsedUrl['query'] === null) {
801
+ $separator = '?';
802
+ }
803
+ }
804
+
805
+ # final url
806
  $url .= $separator.$query;
807
 
808
  # fetch via wordpress functions
1058
  foreach($matches[1] as $a) { $b = trim($a); if($b != $a) { $css = str_replace($a, $b, $css); } }
1059
  $css = preg_replace("/url\(\s*['\"]?(?!data:)(?!http)(?![\/'\"#])(.+?)['\"]?\s*\)/ui", "url(".dirname($url)."/$1)", $css);
1060
  }
1061
+
1062
+
1063
 
1064
  # minify string with relative urls
1065
  if($min) {
1070
  # https://developers.google.com/web/updates/2016/02/font-display
1071
  $css = str_ireplace('font-family:', 'font-display:block;font-family:', $css);
1072
 
1073
+ # make relative urls when possible
1074
+ global $fvm_urls;
1075
+ $bgimgs = array();
1076
+ preg_match_all ('/url\s*\((\s*[\'"]?(http)(s|:).+[\'"]?\s*)\)/Uui', $css, $bgimgs);
1077
+ if(isset($bgimgs[1]) && is_array($bgimgs[1])) {
1078
+ foreach($bgimgs[1] as $img) {
1079
+ if(substr($img, 0, strlen($fvm_urls['wp_home'])) == $fvm_urls['wp_home']) {
1080
+ $pos = strpos($img, $fvm_urls['wp_home']);
1081
+ if ($pos !== false) {
1082
+ $relimg = substr_replace($img, '', $pos, strlen($fvm_urls['wp_home']));
1083
+ $css = str_replace($img, $relimg, $css);
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+
1089
  # return css
1090
  return trim($css);
1091
 
1141
  # return early if empty
1142
  if(empty($css) || $css == false) { return $css; }
1143
 
 
 
 
1144
  # minify
1145
  $minifier = new FVM\MatthiasMullie\Minify\CSS($css);
1146
  $minifier->setMaxImportSize(10); # embed assets up to 10 Kb (default 5Kb) - processes gif, png, jpg, jpeg, svg & woff
1147
  $min = $minifier->minify();
 
 
 
 
 
 
 
 
1148
 
1149
  # return
1150
  if($min != false) {
inc/frontend.php CHANGED
@@ -14,7 +14,6 @@ include_once($fvm_var_inc_lib . DIRECTORY_SEPARATOR . 'raisermin' . DIRECTORY_SE
14
 
15
  # php simple html
16
  # https://sourceforge.net/projects/simplehtmldom/
17
- define('MAX_FILE_SIZE', 2000000); # Process HTML up to 2 Mb
18
  include_once($fvm_var_inc_lib . DIRECTORY_SEPARATOR . 'simplehtmldom' . DIRECTORY_SEPARATOR . 'simple_html_dom.php');
19
 
20
  # PHP Minify [1.3.60] for CSS minification only
@@ -170,7 +169,7 @@ function fvm_process_page($html) {
170
 
171
  # get minification settings for files
172
  if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] == '1') {
173
- $enable_css_minification = true;
174
  }
175
 
176
  # force minification on google fonts
@@ -869,34 +868,44 @@ function fvm_process_page($html) {
869
  }
870
 
871
  # add preload headers
872
- if(is_array($htmlpreloader)) {
873
- ksort($htmlpreloader); # priority
874
- $hm = str_replace('<!-- h_preheader -->', implode(PHP_EOL, $htmlpreloader).'<!-- h_preheader -->', $hm);
 
 
875
  }
876
-
877
  # add critical path
878
- if(is_array($critical_path) && count($critical_path) > 0) {
879
- $hm = str_replace('<!-- h_preheader -->', implode(PHP_EOL, $critical_path).'<!-- h_preheader -->', $hm);
880
- }
881
-
 
 
882
  # add stylesheets
883
- if(is_array($htmlcssheader) && count($htmlcssheader) > 0) {
884
- ksort($htmlcssheader); # priority
885
- $hm = str_replace('<!-- h_cssheader -->', implode(PHP_EOL, $htmlcssheader).'<!-- h_cssheader -->', $hm);
 
 
886
  }
887
 
888
  # add header scripts
889
- if(is_array($htmljscodeheader) && count($htmljscodeheader) > 0) {
890
- ksort($htmljscodeheader); # priority
891
- $hm = str_replace('<!-- h_jsheader -->', implode(PHP_EOL, $htmljscodeheader).'<!-- h_jsheader -->', $hm);
 
 
892
  }
893
-
894
  # add defer scripts
895
- if(is_array($htmljscodedefer) && count($htmljscodedefer) > 0) {
896
- ksort($htmljscodedefer); # priority
897
- $hm = str_replace('<!-- h_jsheader -->', implode(PHP_EOL, $htmljscodedefer), $hm);
 
 
898
  }
899
-
900
  # cleanup leftover markers
901
  $hm = str_replace(
902
  array('<!-- h_preheader -->', '<!-- h_header_function -->', '<!-- h_cssheader -->', '<!-- h_jsheader -->'), '', $hm);
@@ -928,5 +937,3 @@ function fvm_process_page($html) {
928
 
929
  }
930
 
931
-
932
-
14
 
15
  # php simple html
16
  # https://sourceforge.net/projects/simplehtmldom/
 
17
  include_once($fvm_var_inc_lib . DIRECTORY_SEPARATOR . 'simplehtmldom' . DIRECTORY_SEPARATOR . 'simple_html_dom.php');
18
 
19
  # PHP Minify [1.3.60] for CSS minification only
169
 
170
  # get minification settings for files
171
  if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] == '1') {
172
+ $enable_css_minification = false;
173
  }
174
 
175
  # force minification on google fonts
868
  }
869
 
870
  # add preload headers
871
+ if(isset($htmlpreloader)) {
872
+ if(is_array($htmlpreloader)) {
873
+ ksort($htmlpreloader); # priority
874
+ $hm = str_replace('<!-- h_preheader -->', implode(PHP_EOL, $htmlpreloader).'<!-- h_preheader -->', $hm);
875
+ }
876
  }
877
+
878
  # add critical path
879
+ if(isset($critical_path)) {
880
+ if(is_array($critical_path) && count($critical_path) > 0) {
881
+ $hm = str_replace('<!-- h_preheader -->', implode(PHP_EOL, $critical_path).'<!-- h_preheader -->', $hm);
882
+ }
883
+ }
884
+
885
  # add stylesheets
886
+ if(isset($htmlcssheader)) {
887
+ if(is_array($htmlcssheader) && count($htmlcssheader) > 0) {
888
+ ksort($htmlcssheader); # priority
889
+ $hm = str_replace('<!-- h_cssheader -->', implode(PHP_EOL, $htmlcssheader).'<!-- h_cssheader -->', $hm);
890
+ }
891
  }
892
 
893
  # add header scripts
894
+ if(isset($htmljscodeheader)) {
895
+ if(is_array($htmljscodeheader) && count($htmljscodeheader) > 0) {
896
+ ksort($htmljscodeheader); # priority
897
+ $hm = str_replace('<!-- h_jsheader -->', implode(PHP_EOL, $htmljscodeheader).'<!-- h_jsheader -->', $hm);
898
+ }
899
  }
900
+
901
  # add defer scripts
902
+ if(isset($htmljscodedefer)) {
903
+ if(is_array($htmljscodedefer) && count($htmljscodedefer) > 0) {
904
+ ksort($htmljscodedefer); # priority
905
+ $hm = str_replace('<!-- h_jsheader -->', implode(PHP_EOL, $htmljscodedefer), $hm);
906
+ }
907
  }
908
+
909
  # cleanup leftover markers
910
  $hm = str_replace(
911
  array('<!-- h_preheader -->', '<!-- h_header_function -->', '<!-- h_cssheader -->', '<!-- h_jsheader -->'), '', $hm);
937
 
938
  }
939
 
 
 
layout/admin-layout-settings.php CHANGED
@@ -174,8 +174,8 @@
174
  <p class="fvm-bold-green fvm-rowintro"><?php _e( 'Select your options below', 'fast-velocity-minify' ); ?></p>
175
 
176
  <fieldset>
177
- <label for="fvm_settings_css_enable">
178
- <input name="fvm_settings[js][enable]" type="checkbox" id="fvm_settings_css_enable" value="1" <?php echo fvm_get_settings_checkbox(fvm_get_settings_value($fvm_settings, 'js', 'enable')); ?>>
179
  <?php _e( 'Enable JS Processing', 'fast-velocity-minify' ); ?> <span class="note-info">[ <?php _e( 'Will enable processing for the settings below', 'fast-velocity-minify' ); ?> ]</span></label>
180
  <br />
181
 
174
  <p class="fvm-bold-green fvm-rowintro"><?php _e( 'Select your options below', 'fast-velocity-minify' ); ?></p>
175
 
176
  <fieldset>
177
+ <label for="fvm_settings_js_enable">
178
+ <input name="fvm_settings[js][enable]" type="checkbox" id="fvm_settings_js_enable" value="1" <?php echo fvm_get_settings_checkbox(fvm_get_settings_value($fvm_settings, 'js', 'enable')); ?>>
179
  <?php _e( 'Enable JS Processing', 'fast-velocity-minify' ); ?> <span class="note-info">[ <?php _e( 'Will enable processing for the settings below', 'fast-velocity-minify' ); ?> ]</span></label>
180
  <br />
181
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: Alignak
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
4
  Requires at least: 4.7
5
  Requires PHP: 5.6
6
- Stable tag: 3.0.3
7
  Tested up to: 5.6
8
  Text Domain: fast-velocity-minify
9
  License: GPLv3 or later
@@ -55,6 +55,10 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
55
 
56
  == Changelog ==
57
 
 
 
 
 
58
  = 3.0.3 [2020.12.29] =
59
  * Prevent minification on XML content that do not trigger WordPress conditionals
60
  * Added support for critical path positioning before the CSS files when Async mode is enabled
3
  Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
4
  Requires at least: 4.7
5
  Requires PHP: 5.6
6
+ Stable tag: 3.0.4
7
  Tested up to: 5.6
8
  Text Domain: fast-velocity-minify
9
  License: GPLv3 or later
55
 
56
  == Changelog ==
57
 
58
+ = 3.0.4 [2020.12.31] =
59
+ * Improved compatibility on CSS merging with optimole and similar services
60
+ * Fixed some PHP notices and other minor issues
61
+
62
  = 3.0.3 [2020.12.29] =
63
  * Prevent minification on XML content that do not trigger WordPress conditionals
64
  * Added support for critical path positioning before the CSS files when Async mode is enabled