-
AuthorPosts
-
August 17, 2016 at 4:26 pm #673790
Hey there,
i came across these ressources in order to defer javascript.
1. ressource: https://varvy.com/pagespeed/defer-videos.html
1. question: My question: where can i put javascript to bottom of a specific page?2. ressource: https://varvy.com/pagespeed/defer-images.html
2. question: My question: where can i put the script before the end body?and 3rd:
Can i use this code:function defer_parsing_of_js ( $url ) { if ( FALSE === strpos( $url, ‘.js’ ) ) return $url; if ( strpos( $url, ‘jquery.js’ ) ) return $url; return “$url’ defer=’defer”; } add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );
to defer parsing javascript?
So in fact its a noob question, but i would appreciate if you can guide me through.
Thank you very very much!
tobi- This topic was modified 8 years, 4 months ago by Tobiy.
August 21, 2016 at 4:44 am #675153Hey Tobiy,
1. You can use a Code Block.
2. You can use the wp_footer hook:
add_action('wp_footer', function() { ?> CODE <?php });
Best regards,
JosueAugust 21, 2016 at 10:25 am #675284Hey Josue, thank you very much. Let me clarify:
In order to use code on a specific page, i add a code block at the bottom of a page via page layout builder and add the code?Do you mean i type code like thins in function php?
add_action(‘wp_footer’, function() {
?>
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
if ( strpos( $url, ‘jquery.js’ ) ) return $url;
return “$url’ defer=’defer”;
}
add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );
<?php
});Thank you very much!
August 21, 2016 at 4:22 pm #6753611. Use a code block to insert a code per Page.
2. The wp_footer code i posted was a response to (that will apply the code to all pages):
2. question: My question: where can i put the script before the end body?
3. The JS defer code is already a WordPress filter, paste it as it is in functions.php.
August 22, 2016 at 4:44 pm #675866ok this code breaks the site:
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, ‘.js’ ) ) return $url;
if ( strpos( $url, ‘jquery.js’ ) ) return $url;
return “$url’ defer=’defer”;
}
add_filter( ‘clean_url’, ‘defer_parsing_of_js’, 11, 1 );and if i enter the code block the code appears on the page.
So i can just use the code 1. and 2. as you have said? Maybe we have a misunderstanding? I am irritated now…sorry.
- This reply was modified 8 years, 4 months ago by Tobiy.
August 22, 2016 at 5:04 pm #675878Hi,
Can you create me a WordPress administrator account? i can make a page with each script added so you can take that as a reference.
Regards,
JosueAugust 22, 2016 at 6:41 pm #675938This would be so amazing Josue!
- This reply was modified 8 years, 4 months ago by Tobiy.
August 23, 2016 at 1:02 am #676093Ok, 2 and 3 are applied site-wide, 1 is on a Page called “Test”.
Best regards,
JosueAugust 23, 2016 at 9:34 am #676261Josue, you are amazing! Thank you, Thank you, Thank you! Result in gmetrix:PageSpeed Score 100, YSlow Score 98% (argh..google fonts and little stuff, nothing serious). Enfold Team is the best support team ever! Thank you! If anyone else needs help to implement, now i can help too ;-)
- This reply was modified 8 years, 4 months ago by Tobiy.
August 24, 2016 at 7:07 am #676820You are welcome, glad to help :)
Regards,
Josue -
AuthorPosts
- The topic ‘defer videos and images’ is closed to new replies.