Version Description
[2022.08.30] = * legacy code removal and other bugfixes
Download this release
Release Info
Developer | Alignak |
Plugin | Fast Velocity Minify |
Version | 3.2.9 |
Comparing to | |
See all releases |
Code changes from version 3.2.8 to 3.2.9
- fvm.php +1 -2
- inc/common.php +19 -25
- inc/frontend.php +11 -11
- readme.txt +5 -2
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.2.
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
@@ -98,7 +98,6 @@ if(!is_admin()) {
|
|
98 |
|
99 |
# both back and front, as long as the option is enabled
|
100 |
add_action('init', 'fvm_disable_emojis');
|
101 |
-
add_action('wp_loaded', 'fvm_ajax_optimizer');
|
102 |
|
103 |
# both backend and frontend, as long as user can manage options
|
104 |
add_action('admin_bar_menu', 'fvm_admintoolbar', 100);
|
6 |
Author: Raul Peixoto
|
7 |
Author URI: http://fastvelocity.com
|
8 |
Text Domain: fast-velocity-minify
|
9 |
+
Version: 3.2.9
|
10 |
License: GPL2
|
11 |
|
12 |
------------------------------------------------------------------------
|
98 |
|
99 |
# both back and front, as long as the option is enabled
|
100 |
add_action('init', 'fvm_disable_emojis');
|
|
|
101 |
|
102 |
# both backend and frontend, as long as user can manage options
|
103 |
add_action('admin_bar_menu', 'fvm_admintoolbar', 100);
|
inc/common.php
CHANGED
@@ -536,6 +536,11 @@ function fvm_generate_min_url($url, $tkey, $type, $code) {
|
|
536 |
$file = $ch_info['ch_dir'] . DIRECTORY_SEPARATOR . $filename;
|
537 |
$public = $ch_info['ch_url'] . '/' .$filename;
|
538 |
|
|
|
|
|
|
|
|
|
|
|
539 |
# php
|
540 |
if(!file_exists($file) || (file_exists($file) && filemtime($file) < $tvers)) { file_put_contents($file, $code); }
|
541 |
if(file_exists($file)) { return $public; }
|
@@ -2080,13 +2085,6 @@ function fvm_disable_emojis() {
|
|
2080 |
}
|
2081 |
|
2082 |
|
2083 |
-
# stop slow ajax requests for bots
|
2084 |
-
function fvm_ajax_optimizer() {
|
2085 |
-
if(isset($_SERVER['HTTP_USER_AGENT']) && (defined('DOING_AJAX') && DOING_AJAX) || (function_exists('is_ajax') && is_ajax()) || (function_exists('wp_doing_ajax') && wp_doing_ajax())){
|
2086 |
-
if (preg_match('/'.implode('|', array('x11.*ox\/54', 'id\s4.*us.*ome\/62', 'oobo', 'ight', 'tmet', 'eadl', 'ngdo', 'PTST')).'/i', $_SERVER['HTTP_USER_AGENT'])){ echo '0'; exit(); }
|
2087 |
-
}
|
2088 |
-
}
|
2089 |
-
|
2090 |
# rewrite assets to cdn
|
2091 |
function fvm_rewrite_assets_cdn($html) {
|
2092 |
|
@@ -2168,11 +2166,13 @@ function fvm_maybe_download($url) {
|
|
2168 |
|
2169 |
# add our function in the header
|
2170 |
function fvm_add_header_function($html) {
|
2171 |
-
|
2172 |
-
|
2173 |
-
|
2174 |
-
|
2175 |
-
|
|
|
|
|
2176 |
# remove duplicates
|
2177 |
if(stripos($html, $fvmf) !== false) {
|
2178 |
$html = str_ireplace($fvmf, '', $html);
|
@@ -2184,27 +2184,21 @@ function fvm_add_header_function($html) {
|
|
2184 |
}
|
2185 |
|
2186 |
# add lazy load library
|
2187 |
-
function
|
2188 |
-
|
2189 |
-
#
|
2190 |
-
|
2191 |
-
$scripts = <<<'EOF'
|
2192 |
-
<script type='text/javascript' id='fvm-delayjs' data-cfasync='false'>
|
2193 |
-
!function(k,e,x){function r(d,a,g,b){return b=(a?e.getElementById(a):t)||e.createElement(d||"SCRIPT"),a&&(b.id=a),g&&(b.onload=g),b}function u(d){f(function(a){a=[].slice.call(e.querySelectorAll(d));(function v(b,c){if(b=a.shift()){b.parentNode.removeChild(b);var l=b,m,n=void 0;var p=r(l.nodeName);var q=0;for(m=l.attributes;q<m.length;q++)"type"!=(n=m[q]).name&&p.setAttribute(n.name,n.value);(c=(p.text=l.text,p)).src&&!c.hasAttribute("async")?(c.onload=c.onerror=v,e.head.appendChild(c)):(e.head.appendChild(c),
|
2194 |
-
v())}})()})}var f,t,h=[],w=/p/.test(e.readyState);Function();(f=function(d,a){w?x(d,a):h.push(d,a)}).all=u;f.js=function(d,a,g,b){f(function(c){(c=r(t,a,b)).src=d;e.head.appendChild(c)},g)};k.addEventListener("onpageshow"in k?"pageshow":"load",function(){for(w=!u();h[0];)f(h.shift(),h.shift())});k.Defer=f}(this,document,setTimeout);
|
2195 |
-
const userInteractionEvents=["mouseover","keydown","touchstart","touchmove","wheel"];userInteractionEvents.forEach(function(event){window.addEventListener(event,triggerScriptLoader,{passive:!0})});function triggerScriptLoader(){fvmloadscripts();userInteractionEvents.forEach(function(event){window.removeEventListener(event,triggerScriptLoader,{passive:!0})})}function fvmloadscripts(){Defer.all('script[type="fvm-script-delay"]')};
|
2196 |
-
</script>
|
2197 |
-
EOF;
|
2198 |
|
2199 |
# add code
|
2200 |
-
return str_replace('<!-- h_footer_fvm_scripts -->', '<!-- h_footer_fvm_scripts -->' . $scripts, $html);
|
2201 |
|
2202 |
}
|
2203 |
|
2204 |
|
2205 |
# get the domain name
|
2206 |
function fvm_get_scheme() {
|
2207 |
-
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { return 'https'; }
|
|
|
2208 |
if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { return 'https'; }
|
2209 |
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { return 'https'; }
|
2210 |
return 'http';
|
536 |
$file = $ch_info['ch_dir'] . DIRECTORY_SEPARATOR . $filename;
|
537 |
$public = $ch_info['ch_url'] . '/' .$filename;
|
538 |
|
539 |
+
# enforce https on https requests
|
540 |
+
if(parse_url($public, PHP_URL_SCHEME) != fvm_get_scheme()) {
|
541 |
+
$public = str_replace('http://', 'https://', $public);
|
542 |
+
}
|
543 |
+
|
544 |
# php
|
545 |
if(!file_exists($file) || (file_exists($file) && filemtime($file) < $tvers)) { file_put_contents($file, $code); }
|
546 |
if(file_exists($file)) { return $public; }
|
2085 |
}
|
2086 |
|
2087 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2088 |
# rewrite assets to cdn
|
2089 |
function fvm_rewrite_assets_cdn($html) {
|
2090 |
|
2166 |
|
2167 |
# add our function in the header
|
2168 |
function fvm_add_header_function($html) {
|
2169 |
+
|
2170 |
+
# based on wp rocket delay js feature
|
2171 |
+
$fvmf.= <<<'EOF'
|
2172 |
+
<script data-cfasync="false">if(navigator.userAgent.match(/MSIE|Internet Explorer/i)||navigator.userAgent.match(/Trident\/7\..*?rv:11/i)){var href=document.location.href;if(!href.match(/[?&]iebrowser/)){if(href.indexOf("?")==-1){if(href.indexOf("#")==-1){document.location.href=href+"?iebrowser=1"}else{document.location.href=href.replace("#","?iebrowser=1#")}}else{if(href.indexOf("#")==-1){document.location.href=href+"&iebrowser=1"}else{document.location.href=href.replace("#","&iebrowser=1#")}}}}</script>
|
2173 |
+
<script data-cfasync="false">class FVMLoader{constructor(e){this.triggerEvents=e,this.eventOptions={passive:!0},this.userEventListener=this.triggerListener.bind(this),this.delayedScripts={normal:[],async:[],defer:[]},this.allJQueries=[]}_addUserInteractionListener(e){this.triggerEvents.forEach(t=>window.addEventListener(t,e.userEventListener,e.eventOptions))}_removeUserInteractionListener(e){this.triggerEvents.forEach(t=>window.removeEventListener(t,e.userEventListener,e.eventOptions))}triggerListener(){this._removeUserInteractionListener(this),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",this._loadEverythingNow.bind(this)):this._loadEverythingNow()}async _loadEverythingNow(){this._runAllDelayedCSS(),this._delayEventListeners(),this._delayJQueryReady(this),this._handleDocumentWrite(),this._registerAllDelayedScripts(),await this._loadScriptsFromList(this.delayedScripts.normal),await this._loadScriptsFromList(this.delayedScripts.defer),await this._loadScriptsFromList(this.delayedScripts.async),await this._triggerDOMContentLoaded(),await this._triggerWindowLoad(),window.dispatchEvent(new Event("wpr-allScriptsLoaded"))}_registerAllDelayedScripts(){document.querySelectorAll("script[type=fvmdelay]").forEach(e=>{e.hasAttribute("src")?e.hasAttribute("async")&&!1!==e.async?this.delayedScripts.async.push(e):e.hasAttribute("defer")&&!1!==e.defer||"module"===e.getAttribute("data-type")?this.delayedScripts.defer.push(e):this.delayedScripts.normal.push(e):this.delayedScripts.normal.push(e)})}_runAllDelayedCSS(){document.querySelectorAll("link[rel=fvmdelay]").forEach(e=>{e.setAttribute("rel","stylesheet")})}async _transformScript(e){return await this._requestAnimFrame(),new Promise(t=>{const n=document.createElement("script");let r;[...e.attributes].forEach(e=>{let t=e.nodeName;"type"!==t&&("data-type"===t&&(t="type",r=e.nodeValue),n.setAttribute(t,e.nodeValue))}),e.hasAttribute("src")?(n.addEventListener("load",t),n.addEventListener("error",t)):(n.text=e.text,t()),e.parentNode.replaceChild(n,e)})}async _loadScriptsFromList(e){const t=e.shift();return t?(await this._transformScript(t),this._loadScriptsFromList(e)):Promise.resolve()}_delayEventListeners(){let e={};function t(t,n){!function(t){function n(n){return e[t].eventsToRewrite.indexOf(n)>=0?"wpr-"+n:n}e[t]||(e[t]={originalFunctions:{add:t.addEventListener,remove:t.removeEventListener},eventsToRewrite:[]},t.addEventListener=function(){arguments[0]=n(arguments[0]),e[t].originalFunctions.add.apply(t,arguments)},t.removeEventListener=function(){arguments[0]=n(arguments[0]),e[t].originalFunctions.remove.apply(t,arguments)})}(t),e[t].eventsToRewrite.push(n)}function n(e,t){let n=e[t];Object.defineProperty(e,t,{get:()=>n||function(){},set(r){e["wpr"+t]=n=r}})}t(document,"DOMContentLoaded"),t(window,"DOMContentLoaded"),t(window,"load"),t(window,"pageshow"),t(document,"readystatechange"),n(document,"onreadystatechange"),n(window,"onload"),n(window,"onpageshow")}_delayJQueryReady(e){let t=window.jQuery;Object.defineProperty(window,"jQuery",{get:()=>t,set(n){if(n&&n.fn&&!e.allJQueries.includes(n)){n.fn.ready=n.fn.init.prototype.ready=function(t){e.domReadyFired?t.bind(document)(n):document.addEventListener("DOMContentLoaded2",()=>t.bind(document)(n))};const t=n.fn.on;n.fn.on=n.fn.init.prototype.on=function(){if(this[0]===window){function e(e){return e.split(" ").map(e=>"load"===e||0===e.indexOf("load.")?"wpr-jquery-load":e).join(" ")}"string"==typeof arguments[0]||arguments[0]instanceof String?arguments[0]=e(arguments[0]):"object"==typeof arguments[0]&&Object.keys(arguments[0]).forEach(t=>{delete Object.assign(arguments[0],{[e(t)]:arguments[0][t]})[t]})}return t.apply(this,arguments),this},e.allJQueries.push(n)}t=n}})}async _triggerDOMContentLoaded(){this.domReadyFired=!0,await this._requestAnimFrame(),document.dispatchEvent(new Event("DOMContentLoaded2")),await this._requestAnimFrame(),window.dispatchEvent(new Event("DOMContentLoaded2")),await this._requestAnimFrame(),document.dispatchEvent(new Event("wpr-readystatechange")),await this._requestAnimFrame(),document.wpronreadystatechange&&document.wpronreadystatechange()}async _triggerWindowLoad(){await this._requestAnimFrame(),window.dispatchEvent(new Event("wpr-load")),await this._requestAnimFrame(),window.wpronload&&window.wpronload(),await this._requestAnimFrame(),this.allJQueries.forEach(e=>e(window).trigger("wpr-jquery-load")),window.dispatchEvent(new Event("wpr-pageshow")),await this._requestAnimFrame(),window.wpronpageshow&&window.wpronpageshow()}_handleDocumentWrite(){const e=new Map;document.write=document.writeln=function(t){const n=document.currentScript,r=document.createRange(),i=n.parentElement;let a=e.get(n);void 0===a&&(a=n.nextSibling,e.set(n,a));const s=document.createDocumentFragment();r.setStart(s,0),s.appendChild(r.createContextualFragment(t)),i.insertBefore(s,a)}}async _requestAnimFrame(){return new Promise(e=>requestAnimationFrame(e))}static run(){const e=new FVMLoader(["keydown","mousemove","touchmove","touchstart","touchend","wheel"]);e._addUserInteractionListener(e)}}FVMLoader.run();</script>
|
2174 |
+
EOF;
|
2175 |
+
|
2176 |
# remove duplicates
|
2177 |
if(stripos($html, $fvmf) !== false) {
|
2178 |
$html = str_ireplace($fvmf, '', $html);
|
2184 |
}
|
2185 |
|
2186 |
# add lazy load library
|
2187 |
+
function fvm_add_footer_function($html) {
|
2188 |
+
|
2189 |
+
# for further development
|
2190 |
+
#$scripts = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2191 |
|
2192 |
# add code
|
2193 |
+
#return str_replace('<!-- h_footer_fvm_scripts -->', '<!-- h_footer_fvm_scripts -->' . $scripts, $html);
|
2194 |
|
2195 |
}
|
2196 |
|
2197 |
|
2198 |
# get the domain name
|
2199 |
function fvm_get_scheme() {
|
2200 |
+
if(isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') { return 'https'; }
|
2201 |
+
if(isset($_SERVER['HTTPS']) && '1' == $_SERVER['HTTPS']) { return 'https'; }
|
2202 |
if(isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) { return 'https'; }
|
2203 |
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { return 'https'; }
|
2204 |
return 'http';
|
inc/frontend.php
CHANGED
@@ -419,7 +419,8 @@ function fvm_process_page($html) {
|
|
419 |
}
|
420 |
|
421 |
# preload
|
422 |
-
$htmlcssheader[0] = '<link
|
|
|
423 |
|
424 |
}
|
425 |
# END OPTIMIZED FONT DELIVERY
|
@@ -574,7 +575,7 @@ function fvm_process_page($html) {
|
|
574 |
if(isset($scripts_duplicate_check[$uid])) {
|
575 |
$tag->outertext = '';
|
576 |
} else {
|
577 |
-
$tag->type = '
|
578 |
$scripts_duplicate_check[$uid] = $uid;
|
579 |
}
|
580 |
|
@@ -839,7 +840,7 @@ function fvm_process_page($html) {
|
|
839 |
if(stripos($js, $b) !== false || stripos($js, $b) !== false) {
|
840 |
|
841 |
# delay
|
842 |
-
$tag->type = '
|
843 |
|
844 |
# minified
|
845 |
if(!empty($js)) {
|
@@ -861,14 +862,13 @@ function fvm_process_page($html) {
|
|
861 |
foreach ($arr as $b) {
|
862 |
if((stripos($js, $b) !== false || stripos($js, $b) !== false) && !isset($tag->src)) {
|
863 |
|
864 |
-
# defer
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
$tag->innertext = preg_replace('/<!--(.|\s)*?-->/ui', '', $js);
|
870 |
}
|
871 |
-
|
872 |
# unset
|
873 |
unset($allscripts[$k]);
|
874 |
continue 2;
|
@@ -1047,7 +1047,7 @@ function fvm_process_page($html) {
|
|
1047 |
|
1048 |
# add fvm_footer scripts, if enabled
|
1049 |
if(fvm_can_minify_js()) {
|
1050 |
-
$fm =
|
1051 |
}
|
1052 |
|
1053 |
# cleanup leftover markers
|
419 |
}
|
420 |
|
421 |
# preload
|
422 |
+
$htmlcssheader[0] = '<link rel="preload" fetchpriority="low" id="fvmfonts-css" href="'.$css_fonts_url.'" as="style" media="all" onload="this.rel=\'stylesheet\';this.onload=null">';
|
423 |
+
|
424 |
|
425 |
}
|
426 |
# END OPTIMIZED FONT DELIVERY
|
575 |
if(isset($scripts_duplicate_check[$uid])) {
|
576 |
$tag->outertext = '';
|
577 |
} else {
|
578 |
+
$tag->type = 'fvmdelay';
|
579 |
$scripts_duplicate_check[$uid] = $uid;
|
580 |
}
|
581 |
|
840 |
if(stripos($js, $b) !== false || stripos($js, $b) !== false) {
|
841 |
|
842 |
# delay
|
843 |
+
$tag->type = 'fvmdelay';
|
844 |
|
845 |
# minified
|
846 |
if(!empty($js)) {
|
862 |
foreach ($arr as $b) {
|
863 |
if((stripos($js, $b) !== false || stripos($js, $b) !== false) && !isset($tag->src)) {
|
864 |
|
865 |
+
# defer and rawurlencode
|
866 |
+
# jquery document ready needs to execute before deferred scripts
|
867 |
+
if(!empty($js) && stripos($js, ').ready(') === false) {
|
868 |
+
$tag->src = 'data:application/javascript,'.rawurlencode($js);
|
869 |
+
$tag->innertext = '';
|
|
|
870 |
}
|
871 |
+
|
872 |
# unset
|
873 |
unset($allscripts[$k]);
|
874 |
continue 2;
|
1047 |
|
1048 |
# add fvm_footer scripts, if enabled
|
1049 |
if(fvm_can_minify_js()) {
|
1050 |
+
$fm = fvm_add_footer_function($fm);
|
1051 |
}
|
1052 |
|
1053 |
# cleanup leftover markers
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: Alignak
|
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.9
|
5 |
Requires PHP: 5.6
|
6 |
-
Stable tag: 3.2.
|
7 |
-
Tested up to: 6.0.
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
@@ -49,6 +49,9 @@ You need a public directory to store and serve minified cache files. If you need
|
|
49 |
|
50 |
== Changelog ==
|
51 |
|
|
|
|
|
|
|
52 |
= 3.2.8 [2022.05.30] =
|
53 |
* ajax bugfix
|
54 |
|
3 |
Tags: PHP Minify, Lighthouse, GTmetrix, Pingdom, Pagespeed, Merging, Minification, Optimization, Speed, Performance, FVM
|
4 |
Requires at least: 4.9
|
5 |
Requires PHP: 5.6
|
6 |
+
Stable tag: 3.2.9
|
7 |
+
Tested up to: 6.0.2
|
8 |
Text Domain: fast-velocity-minify
|
9 |
License: GPLv3 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
49 |
|
50 |
== Changelog ==
|
51 |
|
52 |
+
= 3.2.9 [2022.08.30] =
|
53 |
+
* legacy code removal and other bugfixes
|
54 |
+
|
55 |
= 3.2.8 [2022.05.30] =
|
56 |
* ajax bugfix
|
57 |
|