Last active
April 6, 2020 18:43
-
-
Save jemekite/28bf43aff8c9830e051c to your computer and use it in GitHub Desktop.
Remove query strings from static resources and Defer parsing of JavaScript for wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _remove_script_version( $src ){ | |
$parts = explode( '?', $src ); | |
return $parts[0]; | |
} | |
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 ); | |
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 ); | |
function defer_parsing_of_js ( $url ) { | |
if ( FALSE === strpos( $url, '.js' ) ) return $url; | |
if ( strpos( $url, 'jquery.js' ) ) return $url; | |
return "$url' async onload='myinit()"; | |
} | |
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