Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created February 20, 2019 21:03
Show Gist options
  • Save fdjones/f1395d81138a525c1101b9c526deae75 to your computer and use it in GitHub Desktop.
Save fdjones/f1395d81138a525c1101b9c526deae75 to your computer and use it in GitHub Desktop.
<script id='script-batch' type='text/javascript'>
(function(d){
var js = d.createElement('script'); js.async = true; js.defer = true;
js.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
d.getElementsByTagName('head')[0].appendChild(js);
})(document);
</script>
@brandonkal
Copy link

function add_async_attribute($tag, $handle) {
    if ( 'my-js-handle' !== $handle )
        return $tag;
    return str_replace( ' src', ' async="async" src', $tag );
}
add_filter('script_loader_tag', 'add_async_attribute', 10, 2);

Note that if both are specified, defer attribute is ignored by browsers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment