RobEarth Softworks
RobEarth Softworks

Reputation: 63

PageSpeed issue "Remove render-blocking JavaScript:" for load-scripts.php in WordPress

We are currently trying to improve our PageSpeed scores but still stuck at 70. One of the remaining issues is below:

Remove render-blocking JavaScript: https://www.example.com/wp-admin/load-scripts.php?c=0&load%5B%5D=jquery-core&ver=4.9.8

This is a WordPress-generated source, but I tried hacking it and added "async" to the script reference but it breaks the site, returning JS errors. Is there any way we can fix this PageSpeed "issue"? Or is this something we should accept as a technical limitation?

Upvotes: 0

Views: 246

Answers (1)

user10341987
user10341987

Reputation:

You'll probably never get a 100/100 score on PageSpeed Insight. You could try adding this function to defer or asynch script files:

// Defer load scripts
function defer_scripts( $tag, $handle, $src ) {

// The handles of the enqueued scripts you want to defer
$defer_scripts = array( 
    'NAME_OF_SCRIPT',
    'ANOTHER_SCRIPT',
);

if ( in_array( $handle, $defer_scripts ) ) {
    return '<script src="' . $src . '" defer="defer" type="text/javascript"></script>' . "\n";
}

return $tag;
} 

add_filter( 'script_loader_tag', 'defer_scripts', 10, 3 );

Upvotes: 0

Related Questions