Eliminate render-blocking JavaScript
-
Hi,
I analyzed my site using Google PageSpeed Insights and got an error
Eliminate render-blocking JavaScript in above-the-fold content
JQuery was one of the package that Google was pointing to
I Googled and came upon some suggestions on how this can be done.
I followed the code given here
function optimize_jquery() { if (!is_admin()) { wp_deregister_script('jquery'); wp_deregister_script('jquery-migrate.min'); wp_deregister_script('comment-reply.min'); $protocol='http:'; if($_SERVER['HTTPS']=='on') { $protocol='https:'; } wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', false, '3.6', true); wp_enqueue_script('jquery'); } } add_action('template_redirect', 'optimize_jquery');While it did remove the JQuery extension from my WordPress’s include folder, the code was still in the <head> tag and not in <body> as was expected.
I then came across this info then which said that sometimes the wp_register_script() last argument of true doesnt necessarily set the code in footer, I followed the suggestion and added true to wp_enqueue_script() last argument, but still no luck.
What am I doing wrong here? How can I make this work and eliminate the render-blocking JavaScript.
The topic ‘Eliminate render-blocking JavaScript’ is closed to new replies.