Version Description
[2020.12.29] = * Prevent minification on XML content that do not trigger WordPress conditionals * Added support for critical path positioning before the CSS files when Async mode is enabled * Minor bugfixes
Download this release
Release Info
Developer | Alignak |
Plugin | Fast Velocity Minify |
Version | 3.0.3 |
Comparing to | |
See all releases |
Code changes from version 3.0.2 to 3.0.3
- fvm.php +1 -1
- inc/common.php +19 -4
- inc/frontend.php +71 -38
- libs/simplehtmldom/simple_html_dom.php +10 -8
- readme.txt +9 -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.
|
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.3
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
inc/common.php
CHANGED
@@ -753,12 +753,13 @@ function fvm_save_log($arr) {
|
|
753 |
|
754 |
|
755 |
|
756 |
-
# try to open the file from the disk, before downloading
|
757 |
# try to open the file from the disk, before downloading
|
758 |
function fvm_maybe_download($url) {
|
759 |
|
760 |
# must have
|
761 |
-
if(is_null($url) || empty($url)) {
|
|
|
|
|
762 |
|
763 |
# get domain
|
764 |
global $fvm_urls;
|
@@ -772,7 +773,12 @@ function fvm_maybe_download($url) {
|
|
772 |
|
773 |
# did it work?
|
774 |
if (file_exists($f)) {
|
775 |
-
|
|
|
|
|
|
|
|
|
|
|
776 |
}
|
777 |
}
|
778 |
|
@@ -990,9 +996,18 @@ function fvm_minify_microdata($data) {
|
|
990 |
|
991 |
# check for php or html, skip if found
|
992 |
function fvm_not_php_html($code) {
|
993 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
994 |
return true;
|
995 |
}
|
|
|
996 |
return false;
|
997 |
}
|
998 |
|
753 |
|
754 |
|
755 |
|
|
|
756 |
# try to open the file from the disk, before downloading
|
757 |
function fvm_maybe_download($url) {
|
758 |
|
759 |
# must have
|
760 |
+
if(is_null($url) || empty($url)) {
|
761 |
+
return array('error'=> __( 'Invalid URL', 'fast-velocity-minify' ));
|
762 |
+
}
|
763 |
|
764 |
# get domain
|
765 |
global $fvm_urls;
|
773 |
|
774 |
# did it work?
|
775 |
if (file_exists($f)) {
|
776 |
+
|
777 |
+
# check contents
|
778 |
+
$code = file_get_contents($f);
|
779 |
+
if(fvm_not_php_html($code)) {
|
780 |
+
return array('content'=>$code, 'src'=>'Disk');
|
781 |
+
}
|
782 |
}
|
783 |
}
|
784 |
|
996 |
|
997 |
# check for php or html, skip if found
|
998 |
function fvm_not_php_html($code) {
|
999 |
+
|
1000 |
+
# return early if not html
|
1001 |
+
$code = trim($code);
|
1002 |
+
$a = '<!doctype';
|
1003 |
+
$b = '<html';
|
1004 |
+
$c = '<?xml';
|
1005 |
+
$d = '<?php';
|
1006 |
+
|
1007 |
+
if ( strcasecmp(substr($code, 0, strlen($a)), $a) != 0 && strcasecmp(substr($code, 0, strlen($b)), $b) != 0 && strcasecmp(substr($code, 0, strlen($c)), $c) != 0 && strcasecmp(substr($code, 0, strlen($d)), $d) != 0 ) {
|
1008 |
return true;
|
1009 |
}
|
1010 |
+
|
1011 |
return false;
|
1012 |
}
|
1013 |
|
inc/frontend.php
CHANGED
@@ -48,7 +48,16 @@ function fvm_process_page($html) {
|
|
48 |
|
49 |
# can process minification?
|
50 |
if(fvm_can_minify()) {
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
# defaults
|
53 |
$tvers = get_option('fvm_last_cache_update', '0');
|
54 |
$now = time();
|
@@ -74,6 +83,7 @@ function fvm_process_page($html) {
|
|
74 |
# defaults
|
75 |
$fvm_styles = array();
|
76 |
$fvm_styles_log = array();
|
|
|
77 |
$enable_css_minification = true;
|
78 |
|
79 |
# exclude styles and link tags inside scripts, no scripts or html comments
|
@@ -238,7 +248,7 @@ function fvm_process_page($html) {
|
|
238 |
$css = '';
|
239 |
|
240 |
# get minification settings for files
|
241 |
-
if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] ==
|
242 |
$enable_css_minification = true;
|
243 |
}
|
244 |
|
@@ -279,6 +289,14 @@ function fvm_process_page($html) {
|
|
279 |
}
|
280 |
}
|
281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
# trim code
|
283 |
$css = trim($css);
|
284 |
|
@@ -615,39 +633,44 @@ function fvm_process_page($html) {
|
|
615 |
|
616 |
# contents
|
617 |
$js = $ddl['content'];
|
618 |
-
|
619 |
# minify, save and wrap
|
620 |
$js = fvm_maybe_minify_js($js, $href, $enable_js_minification);
|
621 |
-
|
622 |
-
# try catch
|
623 |
-
$js = fvm_try_catch_wrap($js);
|
624 |
-
|
625 |
-
# developers filter
|
626 |
-
$js = apply_filters( 'fvm_after_download_and_minify_code', $js, 'js');
|
627 |
-
|
628 |
# quick integrity check
|
629 |
if(!empty($js) && $js != false) {
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
|
631 |
# execution time in ms, size in bytes
|
632 |
$fs = strlen($js);
|
633 |
$ur = str_replace($fvm_urls['wp_home'], '', $href);
|
634 |
$tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
|
635 |
-
|
636 |
# save
|
637 |
fvm_set_transient(array('uid'=>$tkey, 'date'=>$tvers, 'type'=>'js', 'content'=>$js, 'meta'=>$tkey_meta));
|
638 |
-
|
639 |
}
|
640 |
}
|
641 |
}
|
642 |
-
|
643 |
-
#
|
644 |
-
$
|
645 |
-
$scripts_header_log[$tkey] = $tkey;
|
646 |
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
651 |
|
652 |
}
|
653 |
}
|
@@ -680,15 +703,15 @@ function fvm_process_page($html) {
|
|
680 |
# minify, save and wrap
|
681 |
$js = fvm_maybe_minify_js($js, $href, $enable_js_minification);
|
682 |
|
683 |
-
# try catch
|
684 |
-
$js = fvm_try_catch_wrap($js);
|
685 |
-
|
686 |
-
# developers filter
|
687 |
-
$js = apply_filters( 'fvm_after_download_and_minify_code', $js, 'js');
|
688 |
-
|
689 |
# quick integrity check
|
690 |
if(!empty($js) && $js != false) {
|
691 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
692 |
# execution time in ms, size in bytes
|
693 |
$fs = strlen($js);
|
694 |
$ur = str_replace($fvm_urls['wp_home'], '', $href);
|
@@ -700,15 +723,20 @@ function fvm_process_page($html) {
|
|
700 |
}
|
701 |
}
|
702 |
}
|
703 |
-
|
704 |
-
# collect and mark as done for html removal
|
705 |
-
$scripts_footer[$tkey] = $js;
|
706 |
-
$scripts_footer_log[$tkey] = $tkey;
|
707 |
|
708 |
-
#
|
709 |
-
$
|
710 |
-
|
711 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
712 |
|
713 |
}
|
714 |
}
|
@@ -756,7 +784,7 @@ function fvm_process_page($html) {
|
|
756 |
|
757 |
# preload and save for html implementation (with priority order prefix)
|
758 |
$htmlpreloader['c_'.$fheader_url] = '<link rel="preload" href="'.$fheader_url.'" as="script" />';
|
759 |
-
$htmljscodeheader['c_'.$js_header_uid] =
|
760 |
|
761 |
}
|
762 |
|
@@ -795,7 +823,7 @@ function fvm_process_page($html) {
|
|
795 |
|
796 |
# preload and save for html implementation (with priority order prefix)
|
797 |
$htmlpreloader['d_'.$ffooter_url] = '<link rel="preload" href="'.$ffooter_url.'" as="script" />';
|
798 |
-
$htmljscodedefer['d_'.$js_ffooter_uid] =
|
799 |
|
800 |
}
|
801 |
|
@@ -843,7 +871,12 @@ function fvm_process_page($html) {
|
|
843 |
# add preload headers
|
844 |
if(is_array($htmlpreloader)) {
|
845 |
ksort($htmlpreloader); # priority
|
846 |
-
$hm = str_replace('<!-- h_preheader -->', implode(PHP_EOL, $htmlpreloader), $hm);
|
|
|
|
|
|
|
|
|
|
|
847 |
}
|
848 |
|
849 |
# add stylesheets
|
48 |
|
49 |
# can process minification?
|
50 |
if(fvm_can_minify()) {
|
51 |
+
|
52 |
+
# return early if not html
|
53 |
+
$html = trim($html);
|
54 |
+
$a = '<!doctype';
|
55 |
+
$b = '<html';
|
56 |
+
|
57 |
+
if ( strcasecmp(substr($html, 0, strlen($a)), $a) != 0 && strcasecmp(substr($html, 0, strlen($b)), $b) != 0 ) {
|
58 |
+
return $html;
|
59 |
+
}
|
60 |
+
|
61 |
# defaults
|
62 |
$tvers = get_option('fvm_last_cache_update', '0');
|
63 |
$now = time();
|
83 |
# defaults
|
84 |
$fvm_styles = array();
|
85 |
$fvm_styles_log = array();
|
86 |
+
$critical_path = array();
|
87 |
$enable_css_minification = true;
|
88 |
|
89 |
# exclude styles and link tags inside scripts, no scripts or html comments
|
248 |
$css = '';
|
249 |
|
250 |
# get minification settings for files
|
251 |
+
if(isset($fvm_settings['css']['min_disable']) && $fvm_settings['css']['min_disable'] == true) {
|
252 |
$enable_css_minification = true;
|
253 |
}
|
254 |
|
289 |
}
|
290 |
}
|
291 |
|
292 |
+
# critical path needs to come before the CSS file
|
293 |
+
if(isset($fvm_settings['css']['async']) && $fvm_settings['css']['async'] == true) {
|
294 |
+
if(isset($tag->id) && $tag->id == 'critical-path') {
|
295 |
+
$critical_path[] = $tag->outertext;
|
296 |
+
$tag->outertext = '';
|
297 |
+
}
|
298 |
+
}
|
299 |
+
|
300 |
# trim code
|
301 |
$css = trim($css);
|
302 |
|
633 |
|
634 |
# contents
|
635 |
$js = $ddl['content'];
|
636 |
+
|
637 |
# minify, save and wrap
|
638 |
$js = fvm_maybe_minify_js($js, $href, $enable_js_minification);
|
639 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
640 |
# quick integrity check
|
641 |
if(!empty($js) && $js != false) {
|
642 |
+
|
643 |
+
# try catch
|
644 |
+
$js = fvm_try_catch_wrap($js);
|
645 |
+
|
646 |
+
# developers filter
|
647 |
+
$js = apply_filters( 'fvm_after_download_and_minify_code', $js, 'js');
|
648 |
|
649 |
# execution time in ms, size in bytes
|
650 |
$fs = strlen($js);
|
651 |
$ur = str_replace($fvm_urls['wp_home'], '', $href);
|
652 |
$tkey_meta = array('fs'=>$fs, 'url'=>str_replace($fvm_cache_paths['cache_url_min'].'/', '', $ur));
|
653 |
+
|
654 |
# save
|
655 |
fvm_set_transient(array('uid'=>$tkey, 'date'=>$tvers, 'type'=>'js', 'content'=>$js, 'meta'=>$tkey_meta));
|
656 |
+
|
657 |
}
|
658 |
}
|
659 |
}
|
660 |
+
|
661 |
+
# processed successfully?
|
662 |
+
if ($js !== false) {
|
|
|
663 |
|
664 |
+
# collect and mark as done for html removal
|
665 |
+
$scripts_header[$tkey] = $js;
|
666 |
+
$scripts_header_log[$tkey] = $tkey;
|
667 |
+
|
668 |
+
# mark as processed, unset and break inner loop
|
669 |
+
$tag->outertext = '';
|
670 |
+
unset($allscripts[$k]);
|
671 |
+
continue 2;
|
672 |
+
|
673 |
+
}
|
674 |
|
675 |
}
|
676 |
}
|
703 |
# minify, save and wrap
|
704 |
$js = fvm_maybe_minify_js($js, $href, $enable_js_minification);
|
705 |
|
|
|
|
|
|
|
|
|
|
|
|
|
706 |
# quick integrity check
|
707 |
if(!empty($js) && $js != false) {
|
708 |
+
|
709 |
+
# try catch
|
710 |
+
$js = fvm_try_catch_wrap($js);
|
711 |
+
|
712 |
+
# developers filter
|
713 |
+
$js = apply_filters( 'fvm_after_download_and_minify_code', $js, 'js');
|
714 |
+
|
715 |
# execution time in ms, size in bytes
|
716 |
$fs = strlen($js);
|
717 |
$ur = str_replace($fvm_urls['wp_home'], '', $href);
|
723 |
}
|
724 |
}
|
725 |
}
|
|
|
|
|
|
|
|
|
726 |
|
727 |
+
# processed successfully?
|
728 |
+
if ($js !== false) {
|
729 |
+
|
730 |
+
# collect and mark as done for html removal
|
731 |
+
$scripts_footer[$tkey] = $js;
|
732 |
+
$scripts_footer_log[$tkey] = $tkey;
|
733 |
+
|
734 |
+
# mark as processed, unset and break inner loop
|
735 |
+
$tag->outertext = '';
|
736 |
+
unset($allscripts[$k]);
|
737 |
+
continue 2;
|
738 |
+
|
739 |
+
}
|
740 |
|
741 |
}
|
742 |
}
|
784 |
|
785 |
# preload and save for html implementation (with priority order prefix)
|
786 |
$htmlpreloader['c_'.$fheader_url] = '<link rel="preload" href="'.$fheader_url.'" as="script" />';
|
787 |
+
$htmljscodeheader['c_'.$js_header_uid] = '<script data-cfasync="false" src="'.$fheader_url.'"></script>';
|
788 |
|
789 |
}
|
790 |
|
823 |
|
824 |
# preload and save for html implementation (with priority order prefix)
|
825 |
$htmlpreloader['d_'.$ffooter_url] = '<link rel="preload" href="'.$ffooter_url.'" as="script" />';
|
826 |
+
$htmljscodedefer['d_'.$js_ffooter_uid] = '<script data-cfasync="false" defer src="'.$ffooter_url.'"></script>';
|
827 |
|
828 |
}
|
829 |
|
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
|
libs/simplehtmldom/simple_html_dom.php
CHANGED
@@ -18,13 +18,19 @@
|
|
18 |
* Vadim Voituk
|
19 |
* Antcs
|
20 |
*
|
21 |
-
* Version Rev. 1.9.1 (291)
|
22 |
*/
|
23 |
|
24 |
# Exit if accessed directly
|
25 |
if (!defined('ABSPATH')){ exit(); }
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
28 |
define('HDOM_TYPE_ELEMENT', 1);
|
29 |
define('HDOM_TYPE_COMMENT', 2);
|
30 |
define('HDOM_TYPE_TEXT', 3);
|
@@ -42,13 +48,9 @@ define('HDOM_INFO_TEXT', 4);
|
|
42 |
define('HDOM_INFO_INNER', 5);
|
43 |
define('HDOM_INFO_OUTER', 6);
|
44 |
define('HDOM_INFO_ENDSPACE', 7);
|
45 |
-
|
46 |
-
defined('DEFAULT_TARGET_CHARSET') || define('DEFAULT_TARGET_CHARSET', 'UTF-8');
|
47 |
-
defined('DEFAULT_BR_TEXT') || define('DEFAULT_BR_TEXT', "\r\n");
|
48 |
-
defined('DEFAULT_SPAN_TEXT') || define('DEFAULT_SPAN_TEXT', ' ');
|
49 |
-
defined('MAX_FILE_SIZE') || define('MAX_FILE_SIZE', 600000);
|
50 |
define('HDOM_SMARTY_AS_TEXT', 1);
|
51 |
|
|
|
52 |
function file_get_html(
|
53 |
$url,
|
54 |
$use_include_path = false,
|
@@ -62,7 +64,7 @@ function file_get_html(
|
|
62 |
$defaultBRText = DEFAULT_BR_TEXT,
|
63 |
$defaultSpanText = DEFAULT_SPAN_TEXT)
|
64 |
{
|
65 |
-
if($maxLen <= 0) { $maxLen =
|
66 |
|
67 |
$dom = new simple_html_dom(
|
68 |
null,
|
@@ -114,7 +116,7 @@ function str_get_html(
|
|
114 |
$defaultSpanText
|
115 |
);
|
116 |
|
117 |
-
if (empty($str) || strlen($str) >
|
118 |
$dom->clear();
|
119 |
return false;
|
120 |
}
|
18 |
* Vadim Voituk
|
19 |
* Antcs
|
20 |
*
|
21 |
+
* Version Rev. 1.9.1 (291) (edited for FVM)
|
22 |
*/
|
23 |
|
24 |
# Exit if accessed directly
|
25 |
if (!defined('ABSPATH')){ exit(); }
|
26 |
|
27 |
+
# mod
|
28 |
+
defined('FVM_MAX_FILE_SIZE') || define('FVM_MAX_FILE_SIZE', 2000000); # Process HTML up to 2 Mb
|
29 |
+
defined('DEFAULT_TARGET_CHARSET') || define('DEFAULT_TARGET_CHARSET', 'UTF-8');
|
30 |
+
defined('DEFAULT_BR_TEXT') || define('DEFAULT_BR_TEXT', "\r\n");
|
31 |
+
defined('DEFAULT_SPAN_TEXT') || define('DEFAULT_SPAN_TEXT', ' ');
|
32 |
|
33 |
+
# other
|
34 |
define('HDOM_TYPE_ELEMENT', 1);
|
35 |
define('HDOM_TYPE_COMMENT', 2);
|
36 |
define('HDOM_TYPE_TEXT', 3);
|
48 |
define('HDOM_INFO_INNER', 5);
|
49 |
define('HDOM_INFO_OUTER', 6);
|
50 |
define('HDOM_INFO_ENDSPACE', 7);
|
|
|
|
|
|
|
|
|
|
|
51 |
define('HDOM_SMARTY_AS_TEXT', 1);
|
52 |
|
53 |
+
# functions
|
54 |
function file_get_html(
|
55 |
$url,
|
56 |
$use_include_path = false,
|
64 |
$defaultBRText = DEFAULT_BR_TEXT,
|
65 |
$defaultSpanText = DEFAULT_SPAN_TEXT)
|
66 |
{
|
67 |
+
if($maxLen <= 0) { $maxLen = FVM_MAX_FILE_SIZE; }
|
68 |
|
69 |
$dom = new simple_html_dom(
|
70 |
null,
|
116 |
$defaultSpanText
|
117 |
);
|
118 |
|
119 |
+
if (empty($str) || strlen($str) > FVM_MAX_FILE_SIZE) {
|
120 |
$dom->clear();
|
121 |
return false;
|
122 |
}
|
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.
|
7 |
Tested up to: 5.6
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
@@ -30,6 +30,9 @@ I can offer you aditional `custom made` optimization on top of this plugin. If y
|
|
30 |
* Purge all caches on a network site: `wp --url=blog.example.com fvm purge`
|
31 |
* Purge all caches on the entire network (linux): `wp site list --field=url | xargs -n1 -I % wp --url=% fvm purge`
|
32 |
|
|
|
|
|
|
|
33 |
|
34 |
== Installation ==
|
35 |
|
@@ -52,6 +55,11 @@ Version 3.0 is a major code rewrite to improve JS and CSS merging, but it requir
|
|
52 |
|
53 |
== Changelog ==
|
54 |
|
|
|
|
|
|
|
|
|
|
|
55 |
= 3.0.2 [2020.12.29] =
|
56 |
* Added option to preserve settings on uninstall
|
57 |
* Added option to inline all CSS (merging is still the recommended method)
|
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
|
30 |
* Purge all caches on a network site: `wp --url=blog.example.com fvm purge`
|
31 |
* Purge all caches on the entire network (linux): `wp site list --field=url | xargs -n1 -I % wp --url=% fvm purge`
|
32 |
|
33 |
+
= How to add your own critical path ? =
|
34 |
+
You can create a style tag, with an ID equal to "critical-path" ex: `<style id="critical-path"> your code </style>` anywhere on the header and FVM will move it to before the CSS merged files.
|
35 |
+
|
36 |
|
37 |
== Installation ==
|
38 |
|
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
|
61 |
+
* Minor bugfixes
|
62 |
+
|
63 |
= 3.0.2 [2020.12.29] =
|
64 |
* Added option to preserve settings on uninstall
|
65 |
* Added option to inline all CSS (merging is still the recommended method)
|