How do I defer or async this WordPress javascript snippet to load lastly for faster page load times?

后端 未结 10 500
温柔的废话
温柔的废话 2020-12-07 09:28

I have various javascripts that are necessary plugins in one of my WordPress domains, and I know where in the php file it\'s called from.

I\'m taking every measure I

10条回答
  •  隐瞒了意图╮
    2020-12-07 09:41

    Very little modification code Mike Kormendy, which allows you to add 2 attributes at once:

    // Async load
    function add_asyncdefer_attribute($tag, $handle)
    {
        $param = '';
        if ( strpos($handle, 'async') !== false ) $param = 'async ';
        if ( strpos($handle, 'defer') !== false ) $param .= 'defer ';
        if ( $param )
            return str_replace('
    

提交回复
热议问题