Comments (5)
Here you are: f3fa210
from gtm4wp.
Script is loaded from here:
https://github.com/duracelltomi/gtm4wp/blob/master/js/gtm4wp-youtube.js
What I could imagine is to add a dom ready listener and then look at YT iframes in the DOM and only load this code if there are any YT embeds.
from gtm4wp.
I can imagine loading that file with something like this:
function gtm4wp_load_youtube_script() {
global $post;
if (has_block('core-embed/youtube', $post) || (strpos($post->post_content, '<iframe') !== false && strpos($post->post_content, 'youtu') !== false)) {
wp_enqueue_script('gtm4wp-youtube');
}
}
add_action('wp_enqueue_scripts', 'gtm4wp_load_youtube_script');
from gtm4wp.
I am not sure the performance of this code will be good. It scans through the whole post content on the server side increasing processing time and thus, response time.
Checking this in the browser seems to be a better solution for me.
from gtm4wp.
Yes this will definitely put some load on the server, but I believe every WP site now uses some kind of caching - if not, PSI is looking bad and those numbers matter to managers :) So if it's checked on server and then saved in cache in pure html (W3TC, Super Cache, WP Rocket..) it shouldn't add load on server anymore.
I don't like additional scripts because JS is still single threaded and it can block execution of other JS. I'm pretty bad in JS, so I just avoid using JS whenever possible, because when I use it, it has impact on performance - mostly on mobiles.
from gtm4wp.
Related Issues (20)
- Partytown JS HOT 2
- Cannot set Container code to ON HOT 1
- 503 error on cart and checkout HOT 3
- Include new_customer in GA4 purchase too HOT 2
- Unprotected headers used for IP address HOT 4
- `add_shipping_info` and `add_payment_info` events not being triggered by order submit button at checkout HOT 1
- Cannot track add to cart event on products lists HOT 5
- User data for Enhanced Ecommerce HOT 4
- Problem with the "purchase" event HOT 17
- Enhanced conversion email/phone prepping before hashing HOT 10
- Google Tag Manager is loaded even though setting is turned off HOT 12
- String vs id in view_item_details HOT 8
- Uncaught TypeError: Cannot read properties of null (reading 'scrollTop') HOT 2
- view_item only active if variations selected HOT 5
- EVENT PURCHASE DON'T FIRE ON LINK ORDER PAY WOOCOMMERCE HOT 24
- Add Custom Fields to datalayer HOT 8
- Clicking on a product only loads browser after 2-3 secondes. HOT 5
- DataLayer BUG in variable product HOT 7
- PHP Deprecated: Creation of dynamic property WhichBrowser\\Analyser\\Header\\Useragent::$data is deprecated HOT 1
- WebToffee plugin integration consent denied update HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gtm4wp.