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

后端 未结 10 510
温柔的废话
温柔的废话 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:57

    Trying to keep things somewhat modular and all encompassing, the following approach dynamically chooses how to embed the tag with the async or defer attributes by just appending a small identifier to the $handle name:

    /**
    * Add async or defer attributes to script enqueues
    * @author Mike Kormendy
    * @param  String  $tag     The original enqueued 
    
    
    

    Thanks to @MattKeys @crissoca for inspiring my answer here.

提交回复
热议问题