-
AuthorPosts
-
July 27, 2023 at 3:33 pm #1414687
Hello Enfold-Team,
we have a background video embedded at the top of the section on our site https://www.econsor.de/, but we don’t want it to load on mobile, so I enabled the option to hide the video.
The problem is that the video is loading in the background and that is not good for page speed.Do you maybe have an idea so we can stop the video from loading on mobile completely?
Best regards
Maurice SchusterJuly 29, 2023 at 1:33 pm #1414812Hey emilconsor,
Try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:function custom_removesliderVideo_script() { ?> <script> const sliderVideo = document.querySelector("#top.home #youtube .avia-slideshow"); const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0) function removesliderVideo(width){ if(sliderVideo) { if(width <= 768){ sliderVideo.parentNode.removeChild(sliderVideo); } } return } removesliderVideo(viewportWidth); </script> <?php } add_action('wp_footer', 'custom_removesliderVideo_script');
This will remove the slider element in the #youtube color section below 768px, this uses pure javascript so it should occur fast enough for the page speed test to not see the element in the DOM.
Best regards,
MikeAugust 2, 2023 at 1:52 pm #1415252Hello again,
i tried the code which you have send me but it seems like that PageSpeed is still loading the Video. Is there another solution?
i uploaded a screen on WeTransfer: https://we.tl/t-w7TaVGGo8j
Best regards
August 2, 2023 at 5:12 pm #1415268Hi,
I see the code for the script in the source code of your page but it is not being used, it seems to be added via base64 from what looks like WP Rocket.
It seems that your WP Rocket maybe deferring or lazyload the javascript so it is not running, when I test on your site by injecting the javascript it works.
You would need this script to not be deferred by WP Rocket as that allows the video to be loaded and defeats the purpose. This needs to run ASAP so the slideshow is removed before the video is loaded.
I’m not sure if WP Rocket has a way to do this but I recommend trying this with WP Rocket disabled as a test, this script has worked for other users but perhaps they were not deferring or lazyload the javascript as you are.Best regards,
MikeAugust 4, 2023 at 1:02 pm #1415425Hello Mike,
I got the script to work but it is not what we wanted. The problem is that the video is deleted after loading. But we want the video not to load at all in the mobile view. Is there a way to make this as a code?
Best regards
August 4, 2023 at 5:00 pm #1415436Hi,
It doesn’t look like you have this script active on your site right now. I my previous tests in other threads this removes the video before it is loaded as long as the javascript runs early in the page load. It removes the parent div so there is no call for the video and in the other threads it passed a PageSpeed mobile test.
Since it’s not active on your site I’m not sure if your WP Rocket caused it to run after the DOM was loaded or if something else was occuring.
But to answer your question, there is no other way to do this, the only way to determine the screen size of the device loading the page is with javascript, server side PHP can not determine the size of the device loading the page.Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.