Skip to content

Instantly share code, notes, and snippets.

@hsquareweb
Last active November 13, 2017 11:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsquareweb/e83c5cd2cb9372558c2b7a6283bd6402 to your computer and use it in GitHub Desktop.
Save hsquareweb/e83c5cd2cb9372558c2b7a6283bd6402 to your computer and use it in GitHub Desktop.
Defer parsing of JS to speed up WordPress site.
<?php
//Defer parsing of JS to speed up loading pages
if (!(is_admin() )) {
function defer_parsing_of_js ( $url ) {
if ( FALSE === strpos( $url, '.js' ) ) return $url;
if ( strpos( $url, 'jquery.js' ) ) return $url; //excluding js file
return "$url' defer='defer";
}
add_filter( 'clean_url', 'defer_parsing_of_js', 11, 1 );
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment