-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new GTM/GA default exclusion; Fixed typos #395
base: master
Are you sure you want to change the base?
Conversation
J-Rey
commented
Aug 19, 2021
- Fix excluded delayed JS so combined file is still loaded by the browser
- Added new default exclusion for Google Tag Manager & modern Google Analytics
- Minor typos (in console & debug logs)
The steps to update JS is:
|
It seems both patches fix the original issue with missing JS so going with what's now already in the branch |
assets/js/js_delay.min.js
Outdated
const litespeed_ui_events=["mouseover","click","keydown","wheel","touchmove","touchstart"];var litespeed_delay_i=0,urlCreator=window.URL||window.webkitURL;function litespeed_load_delayed_js_forced(){console.log("Start Load JS Delayed"),litespeed_ui_events.forEach(function(e){window.removeEventListener(e,litespeed_load_delayed_js_forced,{passive:!0})}),litespeed_load_delayed_js(!0),document.querySelectorAll("iframe[data-litespeed-src]").forEach(function(e){e.setAttribute("src",e.getAttribute("data-litespeed-src"))})}function litespeed_load_delayed_js(e){e&&console.log("Force running delayed JS"),litespeed_load_one()}function litespeed_inline2src(t){try{var a=urlCreator.createObjectURL(new Blob([t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1")],{type:"text/javascript"}))}catch(e){a="data:text/javascript;base64,"+btoa(t.replace(/^(?:<!--)?(.*?)(?:-->)?$/gm,"$1"))}return a}function litespeed_load_one(){litespeed_delay_i++;var t,a=document.querySelector('script[type="litespeed/javascript"][data-i="'+litespeed_delay_i+'"]');a?(console.log("load i="+a.getAttribute("data-i"),"-----",a),(t=document.createElement("script")).addEventListener("load",function(){console.log("loaded --- "+t.getAttribute("data-i")),litespeed_load_one()},{passive:!0}),a.getAttributeNames().forEach(function(e){"type"!=e&&t.setAttribute("data-src"==e?"src":e,a.getAttribute(e))}),t.type="text/javascript",!t.src&&a.textContent&&(t.src=litespeed_inline2src(a.textContent)),a.after(t),a.remove()):console.log("All loaded!")}litespeed_ui_events.forEach(function(e){window.addEventListener(e,litespeed_load_delayed_js_forced,{passive:!0})}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JS file change needs to change the original file instead of the min ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original js_delay.js needs to be changed too.
src/optimize.cls.php
Outdated
@@ -494,7 +494,7 @@ private function _optimize() { | |||
*/ | |||
private function _build_js_tag( $src ) { | |||
if ( $this->cfg_js_defer === 2 ) { | |||
return '<script data-optimized="1" type="text/javascript" src="' . $src . '"></script>'; | |||
return '<script data-optimized="1" type="litespeed/javascript" data-i="' . ++$this->i2 . '" data-src="' . $src . '"></script>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be in your PR?