Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

J-Rey
Copy link
Contributor

@J-Rey 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)

@hi-hai
Copy link
Collaborator

hi-hai commented Aug 19, 2021

The steps to update JS is:

  1. Update the original JS file.
  2. Go to https://jscompress.com/ to finish compression and update the min file.

@J-Rey J-Rey changed the title Fix excluded delayed JS so still loads; Added new GTM/GA default exclusion Added new GTM/GA default exclusion; Fixed typos Aug 31, 2021
@J-Rey
Copy link
Contributor Author

J-Rey commented Aug 31, 2021

It seems both patches fix the original issue with missing JS so going with what's now already in the branch

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})});
Copy link
Collaborator

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.

Copy link
Collaborator

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.

@@ -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>';
Copy link
Collaborator

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?

@hi-hai hi-hai changed the base branch from dev to master October 31, 2024 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants