Version Description
[2019.01.12] = * fixed the dynamic urls being forced as http:// * fixed the inlined styles being stripped when the inline All CSS option is enabled * added option to disable merging of inlined css code (for when you have dynamic inline css code) * other minor bug fixes
Download this release
Release Info
Developer | Alignak |
Plugin | Fast Velocity Minify |
Version | 2.5.5 |
Comparing to | |
See all releases |
Code changes from version 2.5.4 to 2.5.5
- fvm.php +106 -165
- inc/functions.php +2 -2
- readme.txt +7 -1
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.
|
9 |
License: GPL2
|
10 |
|
11 |
------------------------------------------------------------------------
|
@@ -123,10 +123,12 @@ $enable_defer_js = get_option('fastvelocity_min_enable_defer_js');
|
|
123 |
$exclude_defer_jquery = get_option('fastvelocity_min_exclude_defer_jquery');
|
124 |
$force_inline_css = get_option('fastvelocity_min_force_inline_css');
|
125 |
$force_inline_css_footer = get_option('fastvelocity_min_force_inline_css_footer');
|
|
|
126 |
$remove_googlefonts = get_option('fastvelocity_min_remove_googlefonts');
|
127 |
$defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
|
128 |
$defer_for_pagespeed_optimize = get_option('fastvelocity_min_defer_for_pagespeed_optimize');
|
129 |
$exclude_defer_login = get_option('fastvelocity_min_exclude_defer_login');
|
|
|
130 |
$fvm_fix_editor = get_option('fastvelocity_min_fvm_fix_editor');
|
131 |
$fvmloadcss = get_option('fastvelocity_min_loadcss');
|
132 |
$fvm_remove_css = get_option('fastvelocity_min_fvm_removecss');
|
@@ -240,7 +242,6 @@ if(is_admin()) {
|
|
240 |
# remove query from static assets and process defering (if enabled)
|
241 |
add_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', 10, 2);
|
242 |
add_filter('script_loader_tag', 'fastvelocity_min_defer_js', 10, 3);
|
243 |
-
add_filter('script_loader_tag', 'fastvelocity_min_defer_js_optimize', PHP_INT_MAX, 3);
|
244 |
|
245 |
}
|
246 |
}
|
@@ -253,16 +254,13 @@ global $fvm_fix_editor, $disable_js_merge, $disable_css_merge, $skip_emoji_remov
|
|
253 |
if($fvm_fix_editor == true && is_user_logged_in()) {
|
254 |
remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
|
255 |
remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', 9.999999 );
|
256 |
-
|
257 |
-
remove_filter('style_loader_src', 'fastvelocity_min_merge_css', PHP_INT_MAX, 4);
|
258 |
remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
|
259 |
remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
|
260 |
-
remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_css', 9.999999 );
|
261 |
remove_action('init', 'fastvelocity_min_disable_wp_emojicons');
|
262 |
remove_action('template_redirect', 'fastvelocity_min_html_compression_start', PHP_INT_MAX);
|
263 |
remove_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', 10, 2);
|
264 |
remove_filter('script_loader_tag', 'fastvelocity_min_defer_js', 10, 3);
|
265 |
-
remove_filter('script_loader_tag', 'fastvelocity_min_defer_js_optimize', 10, 3);
|
266 |
}
|
267 |
}
|
268 |
|
@@ -356,6 +354,7 @@ function fastvelocity_min_register_settings() {
|
|
356 |
register_setting('fvm-group', 'fastvelocity_fvm_clean_header_one');
|
357 |
register_setting('fvm-group', 'fastvelocity_min_enable_defer_js');
|
358 |
register_setting('fvm-group', 'fastvelocity_min_exclude_defer_jquery');
|
|
|
359 |
register_setting('fvm-group', 'fastvelocity_min_force_inline_css');
|
360 |
register_setting('fvm-group', 'fastvelocity_min_force_inline_css_footer');
|
361 |
register_setting('fvm-group', 'fastvelocity_min_remove_googlefonts');
|
@@ -364,6 +363,7 @@ function fastvelocity_min_register_settings() {
|
|
364 |
register_setting('fvm-group', 'fastvelocity_min_defer_for_pagespeed');
|
365 |
register_setting('fvm-group', 'fastvelocity_min_defer_for_pagespeed_optimize');
|
366 |
register_setting('fvm-group', 'fastvelocity_min_exclude_defer_login');
|
|
|
367 |
register_setting('fvm-group', 'fastvelocity_min_fvm_fix_editor');
|
368 |
register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_url');
|
369 |
register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_force');
|
@@ -722,7 +722,11 @@ Disable minification on CSS files <span class="note-info">[ If selected, CSS fil
|
|
722 |
<br />
|
723 |
<label for="fastvelocity_min_remove_print_mediatypes">
|
724 |
<input name="fastvelocity_min_remove_print_mediatypes" type="checkbox" id="fastvelocity_min_remove_print_mediatypes" value="1" <?php echo checked(1 == get_option('fastvelocity_min_remove_print_mediatypes'), true, false); ?> >
|
725 |
-
|
|
|
|
|
|
|
|
|
726 |
<br />
|
727 |
<label for="fastvelocity_min_force_inline_css_footer">
|
728 |
<input name="fastvelocity_min_force_inline_css_footer" type="checkbox" id="fastvelocity_min_force_inline_css_footer" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css_footer'), true, false); ?>>
|
@@ -730,7 +734,7 @@ Inline CSS in the footer <span class="note-info">[ If selected, any FVM generate
|
|
730 |
<br />
|
731 |
<label for="fastvelocity_min_force_inline_css">
|
732 |
<input name="fastvelocity_min_force_inline_css" type="checkbox" id="fastvelocity_min_force_inline_css" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css'), true, false); ?>>
|
733 |
-
Inline
|
734 |
<br />
|
735 |
</fieldset></td>
|
736 |
</tr>
|
@@ -761,7 +765,7 @@ Disable minification on JS files <span class="note-info">[ If selected, JS files
|
|
761 |
<p class="fvm-bold-green fvm-rowintro">Some themes and plugins "need" render blocking scripts to work, so please take a look at the dev console for errors.</p>
|
762 |
<label for="fastvelocity_min_enable_defer_js">
|
763 |
<input name="fastvelocity_min_enable_defer_js" type="checkbox" id="fastvelocity_min_enable_defer_js" value="1" <?php echo checked(1 == get_option('fastvelocity_min_enable_defer_js'), true, false); ?>>
|
764 |
-
Enable defer parsing of JS files globally <span class="note-info">[ Not all browsers, themes or plugins support this. Beware of broken functionality and design ]</span></label>
|
765 |
<br />
|
766 |
|
767 |
<label for="fastvelocity_min_exclude_defer_jquery">
|
@@ -770,9 +774,12 @@ Skip deferring the jQuery library <span class="note-info">[ Will probably fix "u
|
|
770 |
<br />
|
771 |
<label for="fastvelocity_min_exclude_defer_login">
|
772 |
<input name="fastvelocity_min_exclude_defer_login" type="checkbox" id="fastvelocity_min_exclude_defer_login" value="1" <?php echo checked(1 == get_option('fastvelocity_min_exclude_defer_login'), true, false); ?> >
|
773 |
-
Skip deferring
|
|
|
|
|
|
|
|
|
774 |
<br />
|
775 |
-
|
776 |
|
777 |
</fieldset></td>
|
778 |
</tr>
|
@@ -784,19 +791,16 @@ Skip deferring completely on the login page <span class="note-info">[ If selecte
|
|
784 |
<fieldset>
|
785 |
<label for="fastvelocity_min_defer_for_pagespeed">
|
786 |
<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); ?>>
|
787 |
-
Enable defer of JS for PSI <span class="note-info">[ Will use JavaScript to defer
|
788 |
|
789 |
<br />
|
790 |
<label for="fastvelocity_min_defer_for_pagespeed_optimize">
|
791 |
<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); ?>>
|
792 |
-
Exclude JS files in the "ignore list" from PSI <span class="note-info">[ This
|
793 |
|
794 |
</fieldset></td>
|
795 |
</tr>
|
796 |
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
</tbody></table>
|
801 |
|
802 |
|
@@ -1570,7 +1574,7 @@ $wp_scripts->done = $done;
|
|
1570 |
# enable defer for JavaScript (WP 4.1 and above) and remove query strings for ignored files
|
1571 |
###########################################
|
1572 |
function fastvelocity_min_defer_js($tag, $handle, $src) {
|
1573 |
-
global $ignore, $blacklist, $ignorelist, $enable_defer_js, $defer_for_pagespeed, $wp_domain, $exclude_defer_login, $fvm_fix_editor, $fvmualist, $
|
1574 |
|
1575 |
# no query strings
|
1576 |
$tag = trim($tag); # must cleanup
|
@@ -1580,63 +1584,72 @@ if (stripos($src, '?ver') !== false) {
|
|
1580 |
$src = $srcf;
|
1581 |
}
|
1582 |
|
1583 |
-
# should we exclude defer on the login page?
|
1584 |
-
if($exclude_defer_login == true && stripos($_SERVER["SCRIPT_NAME"], strrchr(wp_login_url(), '/')) !== false){ return $tag; }
|
1585 |
-
|
1586 |
-
# reprocess the ignore list to remove the /fvm/cache/ from the list (else won't defer)
|
1587 |
-
$nignore = array(); if(is_array($ignore)) { foreach ($ignore as $i) { if($i != '/fvm/cache/') { $nignore[] = $i; } } }
|
1588 |
-
|
1589 |
-
# return if in any ignore list
|
1590 |
-
if (count($nignore) > 0 && fastvelocity_min_in_arrayi($src, $nignore)) { return $tag; }
|
1591 |
-
if (count($blacklist) > 0 && fastvelocity_min_in_arrayi($src, $blacklist)) { return $tag; }
|
1592 |
-
if (count($ignorelist) > 0 && fastvelocity_min_in_arrayi($src, $ignorelist)) { return $tag; }
|
1593 |
-
|
1594 |
# fix page editors
|
1595 |
if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
|
1596 |
|
1597 |
-
# return if
|
1598 |
if ($defer_for_pagespeed != true && $enable_defer_js != true) { return $tag; }
|
1599 |
|
|
|
|
|
|
|
|
|
|
|
1600 |
# return if external script url https://www.chromestatus.com/feature/5718547946799104
|
1601 |
if (fvm_is_local_domain($src) !== true) { return $tag; }
|
1602 |
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
|
1615 |
-
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
-
|
1621 |
-
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
-
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
|
|
|
|
1632 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1633 |
|
1634 |
-
#
|
1635 |
-
if(
|
1636 |
-
return $
|
|
|
|
|
1637 |
}
|
1638 |
}
|
1639 |
-
|
|
|
|
|
1640 |
# fallback
|
1641 |
return $tag;
|
1642 |
}
|
@@ -1644,33 +1657,12 @@ return $tag;
|
|
1644 |
|
1645 |
|
1646 |
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
|
1665 |
-
|
1666 |
-
|
1667 |
-
|
1668 |
###########################################
|
1669 |
# process css #############################
|
1670 |
###########################################
|
1671 |
# collect all css files as well as inline css code, to be printed later
|
1672 |
function fastvelocity_min_merge_css($html, $handle, $href, $media){
|
1673 |
-
global $fvm_debug, $wp_domain, $wp_home, $fvmualist, $fvm_collect_google_fonts, $force_inline_googlefonts, $min_async_googlefonts, $remove_googlefonts, $skip_google_fonts, $css_hide_googlefonts, $remove_print_mediatypes, $ignore, $blacklist, $ignorelist, $fvm_remove_css, $fvm_min_excludecsslist, $disable_css_minification, $fvm_fix_editor, $fvm_fawesome_method, $csscollect;
|
1674 |
|
1675 |
# current timestamp
|
1676 |
$ctime = get_option('fvm-last-cache-update', '0');
|
@@ -1848,27 +1840,24 @@ function fastvelocity_min_merge_css($html, $handle, $href, $media){
|
|
1848 |
# collect main css code from file
|
1849 |
$csscollect[$media][] = array('handle' => $handle, 'log' => $res['log'], 'type'=> 'link', 'code' => $res['code']);
|
1850 |
|
1851 |
-
#
|
1852 |
-
$
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
$hash = md5($code);
|
1862 |
-
$codesize = fastvelocity_format_filesize(strlen($code));
|
1863 |
-
$nlog = "--- Merged $codesize of inlined CSS code for [$handle] with md5 hash: $hash ---" . PHP_EOL;
|
1864 |
-
$csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
|
1865 |
}
|
1866 |
}
|
1867 |
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
|
|
1872 |
if(!empty($code) && $code != false) {
|
1873 |
$hash = md5($code);
|
1874 |
$codesize = fastvelocity_format_filesize(strlen($code));
|
@@ -1876,6 +1865,20 @@ function fastvelocity_min_merge_css($html, $handle, $href, $media){
|
|
1876 |
$csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
|
1877 |
}
|
1878 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1879 |
}
|
1880 |
}
|
1881 |
|
@@ -1981,7 +1984,7 @@ function fastvelocity_add_merged_css(){
|
|
1981 |
if (!file_exists($file)) {
|
1982 |
|
1983 |
# prepare log
|
1984 |
-
$log = "PROCESSED
|
1985 |
|
1986 |
# generate cache, write log
|
1987 |
if(!empty($code)) {
|
@@ -2153,67 +2156,6 @@ if($fvm_headers != false) {
|
|
2153 |
|
2154 |
|
2155 |
|
2156 |
-
###########################################
|
2157 |
-
# optimize the ignore list for pagespeed insights + Exclude JS files from PSI (Async)
|
2158 |
-
###########################################
|
2159 |
-
function fastvelocity_min_defer_js_optimize($tag, $handle, $src) {
|
2160 |
-
global $defer_for_pagespeed, $defer_for_pagespeed_optimize, $fvm_fix_editor, $fvmualist;
|
2161 |
-
|
2162 |
-
# fix page editors
|
2163 |
-
if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
|
2164 |
-
|
2165 |
-
# return if external script url https://www.chromestatus.com/feature/5718547946799104
|
2166 |
-
if (fvm_is_local_domain($src) !== true) { return $tag; }
|
2167 |
-
|
2168 |
-
# filter src for extra atributes
|
2169 |
-
if (stripos($src, '?ver') !== false) {
|
2170 |
-
$src = stristr($src, '?ver', true);
|
2171 |
-
}
|
2172 |
-
|
2173 |
-
# exclude ignored scripts
|
2174 |
-
if(substr($handle, 0, 4) != "fvm-" && $defer_for_pagespeed == true && $defer_for_pagespeed_optimize == true) {
|
2175 |
-
|
2176 |
-
# get available nodes and add create with defer tag (if not async)
|
2177 |
-
$dom = new DOMDocument();
|
2178 |
-
libxml_use_internal_errors(true);
|
2179 |
-
@$dom->loadHTML($tag);
|
2180 |
-
$nodes = $dom->getElementsByTagName('script');
|
2181 |
-
$newtag = '';
|
2182 |
-
if ($nodes->length != 0) {
|
2183 |
-
foreach ($nodes as $k=>$v) {
|
2184 |
-
$node = $dom->getElementsByTagName('script')->item($k);
|
2185 |
-
if ($node->hasAttribute('src')) {
|
2186 |
-
|
2187 |
-
# bypass if there are linebreaks (will break document.write)
|
2188 |
-
if (stripos($ntag, PHP_EOL) !== false || stripos($tag, 'navigator.userAgent.match') !== false) {
|
2189 |
-
$newtag.= $dom->saveHTML($node);
|
2190 |
-
} else {
|
2191 |
-
$ntag = $dom->saveHTML($node);
|
2192 |
-
$newtag.= '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($ntag).');}</script>';
|
2193 |
-
}
|
2194 |
-
|
2195 |
-
} else {
|
2196 |
-
$newtag.= $dom->saveHTML($node);
|
2197 |
-
}
|
2198 |
-
}
|
2199 |
-
|
2200 |
-
# print code if there are no linebreaks, or return
|
2201 |
-
if(!empty($newtag)) {
|
2202 |
-
return $newtag;
|
2203 |
-
}
|
2204 |
-
}
|
2205 |
-
}
|
2206 |
-
|
2207 |
-
# fallback
|
2208 |
-
return $tag;
|
2209 |
-
}
|
2210 |
-
|
2211 |
-
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
|
2216 |
-
|
2217 |
# inline css in place, instead of inlining the large file
|
2218 |
function fastvelocity_optimizecss($html, $handle, $href, $media){
|
2219 |
global $fvm_debug, $wp_domain, $wp_home, $force_inline_css, $fvmualist, $fvm_collect_google_fonts, $force_inline_googlefonts, $min_async_googlefonts, $remove_googlefonts, $skip_google_fonts, $css_hide_googlefonts, $remove_print_mediatypes, $ignore, $blacklist, $ignorelist, $wp_home, $fvmloadcss, $fvm_remove_css, $fvm_cdn_url, $disable_minification, $fvm_min_excludecsslist, $disable_css_minification, $fvm_fix_editor, $fvm_fawesome_method;
|
@@ -2400,7 +2342,6 @@ function fastvelocity_optimizecss($html, $handle, $href, $media){
|
|
2400 |
# get inline_styles for this handle, minify and print
|
2401 |
$inline_styles = array();
|
2402 |
$inline_styles = wp_styles()->get_data( $handle, 'after' );
|
2403 |
-
wp_deregister_style($handle); # remove any inline styles
|
2404 |
if($inline_styles != false) {
|
2405 |
|
2406 |
# string type
|
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.5
|
9 |
License: GPL2
|
10 |
|
11 |
------------------------------------------------------------------------
|
123 |
$exclude_defer_jquery = get_option('fastvelocity_min_exclude_defer_jquery');
|
124 |
$force_inline_css = get_option('fastvelocity_min_force_inline_css');
|
125 |
$force_inline_css_footer = get_option('fastvelocity_min_force_inline_css_footer');
|
126 |
+
$disable_css_inline_merge = get_option('fastvelocity_min_disable_css_inline_merge');
|
127 |
$remove_googlefonts = get_option('fastvelocity_min_remove_googlefonts');
|
128 |
$defer_for_pagespeed = get_option('fastvelocity_min_defer_for_pagespeed');
|
129 |
$defer_for_pagespeed_optimize = get_option('fastvelocity_min_defer_for_pagespeed_optimize');
|
130 |
$exclude_defer_login = get_option('fastvelocity_min_exclude_defer_login');
|
131 |
+
$skip_defer_lists = get_option('fastvelocity_min_skip_defer_lists');
|
132 |
$fvm_fix_editor = get_option('fastvelocity_min_fvm_fix_editor');
|
133 |
$fvmloadcss = get_option('fastvelocity_min_loadcss');
|
134 |
$fvm_remove_css = get_option('fastvelocity_min_fvm_removecss');
|
242 |
# remove query from static assets and process defering (if enabled)
|
243 |
add_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', 10, 2);
|
244 |
add_filter('script_loader_tag', 'fastvelocity_min_defer_js', 10, 3);
|
|
|
245 |
|
246 |
}
|
247 |
}
|
254 |
if($fvm_fix_editor == true && is_user_logged_in()) {
|
255 |
remove_action('wp_print_scripts', 'fastvelocity_min_merge_header_scripts', PHP_INT_MAX );
|
256 |
remove_action('wp_print_footer_scripts', 'fastvelocity_min_merge_footer_scripts', 9.999999 );
|
257 |
+
remove_filter('style_loader_tag', 'fastvelocity_min_merge_css', PHP_INT_MAX, 4 );
|
|
|
258 |
remove_action('wp_print_styles', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX);
|
259 |
remove_action('wp_print_footer_scripts', 'fastvelocity_add_google_fonts_merged', PHP_INT_MAX );
|
|
|
260 |
remove_action('init', 'fastvelocity_min_disable_wp_emojicons');
|
261 |
remove_action('template_redirect', 'fastvelocity_min_html_compression_start', PHP_INT_MAX);
|
262 |
remove_filter('style_loader_src', 'fastvelocity_remove_cssjs_ver', 10, 2);
|
263 |
remove_filter('script_loader_tag', 'fastvelocity_min_defer_js', 10, 3);
|
|
|
264 |
}
|
265 |
}
|
266 |
|
354 |
register_setting('fvm-group', 'fastvelocity_fvm_clean_header_one');
|
355 |
register_setting('fvm-group', 'fastvelocity_min_enable_defer_js');
|
356 |
register_setting('fvm-group', 'fastvelocity_min_exclude_defer_jquery');
|
357 |
+
register_setting('fvm-group', 'fastvelocity_min_disable_css_inline_merge');
|
358 |
register_setting('fvm-group', 'fastvelocity_min_force_inline_css');
|
359 |
register_setting('fvm-group', 'fastvelocity_min_force_inline_css_footer');
|
360 |
register_setting('fvm-group', 'fastvelocity_min_remove_googlefonts');
|
363 |
register_setting('fvm-group', 'fastvelocity_min_defer_for_pagespeed');
|
364 |
register_setting('fvm-group', 'fastvelocity_min_defer_for_pagespeed_optimize');
|
365 |
register_setting('fvm-group', 'fastvelocity_min_exclude_defer_login');
|
366 |
+
register_setting('fvm-group', 'fastvelocity_min_skip_defer_lists');
|
367 |
register_setting('fvm-group', 'fastvelocity_min_fvm_fix_editor');
|
368 |
register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_url');
|
369 |
register_setting('fvm-group', 'fastvelocity_min_fvm_cdn_force');
|
722 |
<br />
|
723 |
<label for="fastvelocity_min_remove_print_mediatypes">
|
724 |
<input name="fastvelocity_min_remove_print_mediatypes" type="checkbox" id="fastvelocity_min_remove_print_mediatypes" value="1" <?php echo checked(1 == get_option('fastvelocity_min_remove_print_mediatypes'), true, false); ?> >
|
725 |
+
Disable the "Print" related stylesheets <span class="note-info">[ If selected, CSS files of mediatype "print" will be removed from the site ]</span></label>
|
726 |
+
<br />
|
727 |
+
<label for="fastvelocity_min_disable_css_inline_merge">
|
728 |
+
<input name="fastvelocity_min_disable_css_inline_merge" type="checkbox" id="fastvelocity_min_disable_css_inline_merge" value="1" <?php echo checked(1 == get_option('fastvelocity_min_disable_css_inline_merge'), true, false); ?>>
|
729 |
+
Disable merging of inlined CSS code <span class="note-info">[ If selected, existing inline CSS will be inlined after the FVM generated CSS file instead of merged together]</span></label>
|
730 |
<br />
|
731 |
<label for="fastvelocity_min_force_inline_css_footer">
|
732 |
<input name="fastvelocity_min_force_inline_css_footer" type="checkbox" id="fastvelocity_min_force_inline_css_footer" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css_footer'), true, false); ?>>
|
734 |
<br />
|
735 |
<label for="fastvelocity_min_force_inline_css">
|
736 |
<input name="fastvelocity_min_force_inline_css" type="checkbox" id="fastvelocity_min_force_inline_css" value="1" <?php echo checked(1 == get_option('fastvelocity_min_force_inline_css'), true, false); ?>>
|
737 |
+
Inline CSS both in the header and footer <span class="note-info">[ If selected, any FVM generated CSS files (header + footer) will be inlined ]</span></label>
|
738 |
<br />
|
739 |
</fieldset></td>
|
740 |
</tr>
|
765 |
<p class="fvm-bold-green fvm-rowintro">Some themes and plugins "need" render blocking scripts to work, so please take a look at the dev console for errors.</p>
|
766 |
<label for="fastvelocity_min_enable_defer_js">
|
767 |
<input name="fastvelocity_min_enable_defer_js" type="checkbox" id="fastvelocity_min_enable_defer_js" value="1" <?php echo checked(1 == get_option('fastvelocity_min_enable_defer_js'), true, false); ?>>
|
768 |
+
Enable defer parsing of FVM JS files globally <span class="note-info">[ Not all browsers, themes or plugins support this. Beware of broken functionality and design ]</span></label>
|
769 |
<br />
|
770 |
|
771 |
<label for="fastvelocity_min_exclude_defer_jquery">
|
774 |
<br />
|
775 |
<label for="fastvelocity_min_exclude_defer_login">
|
776 |
<input name="fastvelocity_min_exclude_defer_login" type="checkbox" id="fastvelocity_min_exclude_defer_login" value="1" <?php echo checked(1 == get_option('fastvelocity_min_exclude_defer_login'), true, false); ?> >
|
777 |
+
Skip deferring JS on the login page <span class="note-info">[ If selected, will disable JS deferring on your login page ]</span></label>
|
778 |
+
<br />
|
779 |
+
<label for="fastvelocity_min_skip_defer_lists">
|
780 |
+
<input name="fastvelocity_min_skip_defer_lists" type="checkbox" id="fastvelocity_min_skip_defer_lists" value="1" <?php echo checked(1 == get_option('fastvelocity_min_skip_defer_lists'), true, false); ?> >
|
781 |
+
Skip deferring the ignore list <span class="note-info">[ If selected, files on the blacklist, ignore list, etc, won't be deferred ]</span></label>
|
782 |
<br />
|
|
|
783 |
|
784 |
</fieldset></td>
|
785 |
</tr>
|
791 |
<fieldset>
|
792 |
<label for="fastvelocity_min_defer_for_pagespeed">
|
793 |
<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); ?>>
|
794 |
+
Enable defer of all JS files for PSI only <span class="note-info">[ Will use JavaScript to defer all JS files for PSI ]</span></label>
|
795 |
|
796 |
<br />
|
797 |
<label for="fastvelocity_min_defer_for_pagespeed_optimize">
|
798 |
<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); ?>>
|
799 |
+
Exclude JS files in the "ignore list" from PSI <span class="note-info">[ This will hide the "ignored files" from PSI instead of simply deferring ]</span></label>
|
800 |
|
801 |
</fieldset></td>
|
802 |
</tr>
|
803 |
|
|
|
|
|
|
|
804 |
</tbody></table>
|
805 |
|
806 |
|
1574 |
# enable defer for JavaScript (WP 4.1 and above) and remove query strings for ignored files
|
1575 |
###########################################
|
1576 |
function fastvelocity_min_defer_js($tag, $handle, $src) {
|
1577 |
+
global $ignore, $blacklist, $ignorelist, $enable_defer_js, $defer_for_pagespeed, $wp_domain, $exclude_defer_login, $fvm_fix_editor, $fvmualist, $defer_for_pagespeed_optimize, $exclude_defer_jquery, $skip_defer_lists;
|
1578 |
|
1579 |
# no query strings
|
1580 |
$tag = trim($tag); # must cleanup
|
1584 |
$src = $srcf;
|
1585 |
}
|
1586 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1587 |
# fix page editors
|
1588 |
if($fvm_fix_editor == true && is_user_logged_in()) { return $tag; }
|
1589 |
|
1590 |
+
# return if defer option is not selected
|
1591 |
if ($defer_for_pagespeed != true && $enable_defer_js != true) { return $tag; }
|
1592 |
|
1593 |
+
# Skip deferring the jQuery library option
|
1594 |
+
if($exclude_defer_jquery != false && (stripos($tag, '/jquery.js') !== false || stripos($tag, '/jquery.min.js') !== false || (stripos($tag, '/jquery-') !== false && stripos($tag, '.js') !== false))) {
|
1595 |
+
return $tag;
|
1596 |
+
}
|
1597 |
+
|
1598 |
# return if external script url https://www.chromestatus.com/feature/5718547946799104
|
1599 |
if (fvm_is_local_domain($src) !== true) { return $tag; }
|
1600 |
|
1601 |
+
# bypass if there are linebreaks (will break document.write) or already being optimized
|
1602 |
+
if (stripos($tag, PHP_EOL) !== false || stripos($tag, 'navigator.userAgent.match') !== false) {
|
1603 |
+
return $tag;
|
1604 |
+
}
|
1605 |
+
|
1606 |
+
# should we exclude defer on the login page?
|
1607 |
+
if($exclude_defer_login == true && stripos($_SERVER["SCRIPT_NAME"], strrchr(wp_login_url(), '/')) !== false){
|
1608 |
+
return $tag;
|
1609 |
+
}
|
1610 |
+
|
1611 |
+
# add defer attribute, but only if not having async or defer already
|
1612 |
+
if (stripos($tag, 'defer') === false && stripos($tag, 'async') === false) {
|
1613 |
+
|
1614 |
+
# defer tag globally
|
1615 |
+
$jsdefer = str_ireplace('<script ', '<script defer ', $tag);
|
1616 |
+
|
1617 |
+
# defer tag for PSI only
|
1618 |
+
$jsdeferpsionly = '<script type="text/javascript">if(navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($jsdefer).');}else{document.write('.json_encode($tag).');}</script>';
|
1619 |
+
|
1620 |
+
# hide tag from PSI
|
1621 |
+
$jsdeferhidepsi = '<script type="text/javascript">if(!navigator.userAgent.match(/'.implode('|', $fvmualist).'/i)){document.write('.json_encode($tag).');}</script>';
|
1622 |
+
|
1623 |
+
# must return by this order...
|
1624 |
+
|
1625 |
+
# remove FVM from the ignore list
|
1626 |
+
array_filter($ignore, function ($var) { return (stripos($var, '/fvm/') === false); });
|
1627 |
+
|
1628 |
+
# Exclude JS files in the "ignore list" from PSI
|
1629 |
+
if($defer_for_pagespeed_optimize != false) {
|
1630 |
+
if((count($ignore) > 0 && fastvelocity_min_in_arrayi($src, $nignore)) || (count($blacklist) > 0 && fastvelocity_min_in_arrayi($src, $blacklist)) || (count($ignorelist) > 0 && fastvelocity_min_in_arrayi($src, $ignorelist))) {
|
1631 |
+
return $jsdeferhidepsi;
|
1632 |
}
|
1633 |
+
}
|
1634 |
+
|
1635 |
+
# Enable defer of JS files for PSI
|
1636 |
+
if($defer_for_pagespeed != false) {
|
1637 |
+
return $jsdeferpsionly;
|
1638 |
+
}
|
1639 |
+
|
1640 |
+
# Enable defer parsing of FVM JS files globally
|
1641 |
+
if($enable_defer_js == true) {
|
1642 |
|
1643 |
+
# consider "Skip deferring the ignore list"
|
1644 |
+
if($skip_defer_lists != false && ((count($nignore) > 0 && fastvelocity_min_in_arrayi($src, $nignore)) || (count($blacklist) > 0 && fastvelocity_min_in_arrayi($src, $blacklist)) || (count($ignorelist) > 0 && fastvelocity_min_in_arrayi($src, $ignorelist)))) {
|
1645 |
+
return $tag;
|
1646 |
+
} else {
|
1647 |
+
return $jsdefer;
|
1648 |
}
|
1649 |
}
|
1650 |
+
|
1651 |
+
}
|
1652 |
+
|
1653 |
# fallback
|
1654 |
return $tag;
|
1655 |
}
|
1657 |
|
1658 |
|
1659 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1660 |
###########################################
|
1661 |
# process css #############################
|
1662 |
###########################################
|
1663 |
# collect all css files as well as inline css code, to be printed later
|
1664 |
function fastvelocity_min_merge_css($html, $handle, $href, $media){
|
1665 |
+
global $fvm_debug, $wp_domain, $wp_home, $fvmualist, $fvm_collect_google_fonts, $force_inline_googlefonts, $min_async_googlefonts, $remove_googlefonts, $skip_google_fonts, $css_hide_googlefonts, $remove_print_mediatypes, $ignore, $blacklist, $ignorelist, $fvm_remove_css, $fvm_min_excludecsslist, $disable_css_minification, $fvm_fix_editor, $fvm_fawesome_method, $csscollect, $disable_css_inline_merge;
|
1666 |
|
1667 |
# current timestamp
|
1668 |
$ctime = get_option('fvm-last-cache-update', '0');
|
1840 |
# collect main css code from file
|
1841 |
$csscollect[$media][] = array('handle' => $handle, 'log' => $res['log'], 'type'=> 'link', 'code' => $res['code']);
|
1842 |
|
1843 |
+
# merge inline css code, unless disabled
|
1844 |
+
if($disable_css_inline_merge != true) {
|
1845 |
+
|
1846 |
+
# get inline_styles for this handle
|
1847 |
+
$inline_styles = array();
|
1848 |
+
global $wp_styles;
|
1849 |
+
if(is_object($wp_styles)) {
|
1850 |
+
if(isset($wp_styles->registered[$handle]->extra['after'])) {
|
1851 |
+
$inline_styles = $wp_styles->registered[$handle]->extra['after'];
|
1852 |
+
unset($wp_styles->registered[$handle]->extra['after']);
|
|
|
|
|
|
|
|
|
1853 |
}
|
1854 |
}
|
1855 |
|
1856 |
+
if($inline_styles != false) {
|
1857 |
+
|
1858 |
+
# string type
|
1859 |
+
if(is_string($inline_styles) && !empty($inline_styles)) {
|
1860 |
+
$code = fastvelocity_min_get_css($href, $inline_styles, $disable_css_minification);
|
1861 |
if(!empty($code) && $code != false) {
|
1862 |
$hash = md5($code);
|
1863 |
$codesize = fastvelocity_format_filesize(strlen($code));
|
1865 |
$csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
|
1866 |
}
|
1867 |
}
|
1868 |
+
|
1869 |
+
# array type
|
1870 |
+
if(is_array($inline_styles)) {
|
1871 |
+
$inline_styles = array_filter($inline_styles);
|
1872 |
+
foreach ($inline_styles as $st) {
|
1873 |
+
$code = fastvelocity_min_get_css($href, $st, $disable_css_minification);
|
1874 |
+
if(!empty($code) && $code != false) {
|
1875 |
+
$hash = md5($code);
|
1876 |
+
$codesize = fastvelocity_format_filesize(strlen($code));
|
1877 |
+
$nlog = "--- Merged $codesize of inlined CSS code for [$handle] with md5 hash: $hash ---" . PHP_EOL;
|
1878 |
+
$csscollect[$media][] = array('handle' => $handle, 'log' => $nlog, 'type'=> 'inline', 'code' => $code, 'hash'=>$hash);
|
1879 |
+
}
|
1880 |
+
}
|
1881 |
+
}
|
1882 |
}
|
1883 |
}
|
1884 |
|
1984 |
if (!file_exists($file)) {
|
1985 |
|
1986 |
# prepare log
|
1987 |
+
$log = "PROCESSED - " . home_url(add_query_arg(NULL, NULL)) . PHP_EOL . "GENERATED - " . date('r') . PHP_EOL . 'MEDIATYPE - '.$mediatype . PHP_EOL . '---' . PHP_EOL . $log;
|
1988 |
|
1989 |
# generate cache, write log
|
1990 |
if(!empty($code)) {
|
2156 |
|
2157 |
|
2158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2159 |
# inline css in place, instead of inlining the large file
|
2160 |
function fastvelocity_optimizecss($html, $handle, $href, $media){
|
2161 |
global $fvm_debug, $wp_domain, $wp_home, $force_inline_css, $fvmualist, $fvm_collect_google_fonts, $force_inline_googlefonts, $min_async_googlefonts, $remove_googlefonts, $skip_google_fonts, $css_hide_googlefonts, $remove_print_mediatypes, $ignore, $blacklist, $ignorelist, $wp_home, $fvmloadcss, $fvm_remove_css, $fvm_cdn_url, $disable_minification, $fvm_min_excludecsslist, $disable_css_minification, $fvm_fix_editor, $fvm_fawesome_method;
|
2342 |
# get inline_styles for this handle, minify and print
|
2343 |
$inline_styles = array();
|
2344 |
$inline_styles = wp_styles()->get_data( $handle, 'after' );
|
|
|
2345 |
if($inline_styles != false) {
|
2346 |
|
2347 |
# string type
|
inc/functions.php
CHANGED
@@ -135,7 +135,7 @@ function fastvelocity_plugin_activate() {
|
|
135 |
fvm_cache_increment();
|
136 |
|
137 |
# default options to enable (1)
|
138 |
-
$options_enable_default = array('fastvelocity_min_remove_print_mediatypes', 'fastvelocity_fvm_clean_header_one', 'fastvelocity_min_skip_google_fonts', 'fastvelocity_min_force_inline_css_footer', 'fastvelocity_min_skip_cssorder', 'fastvelocity_gfonts_method', 'fastvelocity_fontawesome_method');
|
139 |
foreach($options_enable_default as $option) {
|
140 |
update_option($option, 1, 'yes');
|
141 |
}
|
@@ -228,7 +228,7 @@ $default_protocol = $default_protocol.'://';
|
|
228 |
$wp_home = rtrim($wp_home, '/');
|
229 |
|
230 |
# apply some filters
|
231 |
-
if (substr($hurl, 0, 2) === "//") { $hurl =
|
232 |
if (substr($hurl, 0, 4) === "http" && stripos($hurl, $wp_domain) === false) { return $hurl; } # return if external domain
|
233 |
if (substr($hurl, 0, 4) !== "http" && stripos($hurl, $wp_domain) !== false) { $hurl = $wp_home.'/'.ltrim($hurl, "/"); } # protocol + home
|
234 |
|
135 |
fvm_cache_increment();
|
136 |
|
137 |
# default options to enable (1)
|
138 |
+
$options_enable_default = array('fastvelocity_min_remove_print_mediatypes', 'fastvelocity_fvm_clean_header_one', 'fastvelocity_min_skip_google_fonts', 'fastvelocity_min_force_inline_css_footer', 'fastvelocity_min_skip_cssorder', 'fastvelocity_gfonts_method', 'fastvelocity_fontawesome_method', 'fastvelocity_min_disable_css_inline_merge');
|
139 |
foreach($options_enable_default as $option) {
|
140 |
update_option($option, 1, 'yes');
|
141 |
}
|
228 |
$wp_home = rtrim($wp_home, '/');
|
229 |
|
230 |
# apply some filters
|
231 |
+
if (substr($hurl, 0, 2) === "//") { $hurl = $default_protocol.ltrim($hurl, "/"); } # protocol only
|
232 |
if (substr($hurl, 0, 4) === "http" && stripos($hurl, $wp_domain) === false) { return $hurl; } # return if external domain
|
233 |
if (substr($hurl, 0, 4) !== "http" && stripos($hurl, $wp_domain) !== false) { $hurl = $wp_home.'/'.ltrim($hurl, "/"); } # protocol + home
|
234 |
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
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.
|
6 |
Tested up to: 5.0.3
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
@@ -201,6 +201,12 @@ If you would like to donate any amount to the plugin author (thank you in advanc
|
|
201 |
|
202 |
== Changelog ==
|
203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
204 |
= 2.5.4 [2019.01.11] =
|
205 |
* css merging bug fixes
|
206 |
|
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.5
|
6 |
Tested up to: 5.0.3
|
7 |
License: GPLv3 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
201 |
|
202 |
== Changelog ==
|
203 |
|
204 |
+
= 2.5.5 [2019.01.12] =
|
205 |
+
* fixed the dynamic urls being forced as http://
|
206 |
+
* fixed the inlined styles being stripped when the inline All CSS option is enabled
|
207 |
+
* added option to disable merging of inlined css code (for when you have dynamic inline css code)
|
208 |
+
* other minor bug fixes
|
209 |
+
|
210 |
= 2.5.4 [2019.01.11] =
|
211 |
* css merging bug fixes
|
212 |
|