[wp-trac] [WordPress Trac] #58632: Add support for 'async' and 'defer' loading to script that use inline scripts.

WordPress Trac noreply at wordpress.org
Mon Oct 16 16:50:11 UTC 2023


#58632: Add support for 'async' and 'defer' loading to script that use inline
scripts.
---------------------------+------------------------------
 Reporter:  joemcgill      |       Owner:  (none)
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Script Loader  |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:  performance
---------------------------+------------------------------

Comment (by JG Visual):

 This may not be the best place to note this, but I wanted to add another
 relevant use case here.

 Below I've included the default Google Analytics 4 JavaScript. Ideally you
 could load the `https://www.googletagmanager.com/gtag/js` script `async`
 by including the strategy. Unfortunately it's not possible since an inline
 script also needs to be attached.

 Given that Google Analytics is used on tons of websites and some
 developers may prefer to load it without a plugin, allowing for
 `wp_register_script()` and `wp_enqueue_script()` to work as expected here
 would be helpful.

 {{{
 <!-- Google tag (gtag.js) -->
 <script async
 src="https://www.googletagmanager.com/gtag/js?id=G-00000000"></script>
 <script>
   window.dataLayer = window.dataLayer || [];
   function gtag(){dataLayer.push(arguments);}
   gtag('js', new Date());

   gtag('config', 'G-00000000');
 </script>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58632#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list