Title: Defer attribute on scripts being removed?
Last modified: October 14, 2025

---

# Defer attribute on scripts being removed?

 *  Resolved [Jamie Burchell](https://wordpress.org/support/users/jamieburchell/)
 * (@jamieburchell)
 * [6 months, 1 week ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/)
 * Run in to a problem with the “defer” attribute being removed from my scripts 
   on one of my websites.
 * When W3TC is disabled, both scripts have the defer attribute:
 *     ```wp-block-code
       <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=X&amp;ver=2.0.2" id="gforms_recaptcha_recaptcha-js" defer="defer" data-wp-strategy="defer"></script><script type="text/javascript" src="https://example.com/app/plugins/gravityformsrecaptcha/js/frontend.min.js?x39172&amp;ver=2.0.2" id="gforms_recaptcha_frontend-js" defer="defer" data-wp-strategy="defer"></script>
       ```
   
 * When W3TC is enabled, the minified version has the attribute removed:
 *     ```wp-block-code
       <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=X&amp;ver=2.0.2" id="gforms_recaptcha_recaptcha-js" defer="defer" data-wp-strategy="defer"></script><script  src="https://example.com/app/cache/minify/e2eea.js?x39172"></script>
       ```
   
 * This causes a problem, since the `e2eea` script requires the reCAPTCHA library.
 * Curiously, on one of my other websites this is not happening:
 * When W3TC is enabled, the minified version has a single “defer” attribute (preserved):
 *     ```wp-block-code
       <script src="https://www.google.com/recaptcha/api.js?render=X&amp;ver=2.0.2" id="gforms_recaptcha_recaptcha-js" defer data-wp-strategy="defer"></script><script  defer src="https://example.co.uk/app/cache/minify/e2eea.js?x14114"></script>
       ```
   
 * As far as I can tell, the W3TC configurations are pretty much the same for both
   websites:
 *     ```wp-block-code
       diff broken working67c67<     "lazyload.enabled": true,--->     "lazyload.enabled": false,1078,1080c1078,1080<     "page": "w3tc_minify",<     "_wpnonce": "e692661fe3",<     "_wp_http_referer": "\/wp\/wp-admin\/admin.php?page=w3tc_minify&w3tc_message=68ee51307695c&w3tc_note=flush_all",--->     "page": "w3tc_general",>     "_wpnonce": "beaaf92399",>     "_wp_http_referer": "\/wp\/wp-admin\/admin.php?page=w3tc_general",1131,1134c1131,1132<     "allcache.wp_cron": "0",<     "pgcache.wp_cron": "0",<     "minify.wp_cron": "0"< }--->     "allcache.wp_cron": "0"> }\ No newline at end of file
       ```
   
 * Both websites are running W3TC 2.8.13, Gravity Forms reCAPTCHA 2.0.2. The working
   website is an Elementor website, the other a WPBakery website, but I cannot fathom
   why one is getting the defer script stripped out?

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 months, 1 week ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18680994)
 * Hello [@jamieburchell](https://wordpress.org/support/users/jamieburchell/)
 * Thank you for reaching out and I am happy to help!
 * Can you please go to the Minify advanced settings in Performance>Minify, and 
   under the JS section, check the embed type for Minify Engine settings:
 * ![](https://i0.wp.com/i.imgur.com/WJKpYN4.png?ssl=1)
 * Let me know if there is a difference in the configuration on those websites when
   it comes to this option, and let me know if selecting this Embed type helps
 * Thanks!
 *  Thread Starter [Jamie Burchell](https://wordpress.org/support/users/jamieburchell/)
 * (@jamieburchell)
 * [6 months, 1 week ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18681144)
 * Hi [@vmarko](https://wordpress.org/support/users/vmarko/)
 * Both options on both websites are set to “Default (Blocking)”
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 months ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18689622)
 * Hello [@jamieburchell](https://wordpress.org/support/users/jamieburchell/)
 * Sorry for the late reply. I was trying to replicate the problem however, I was
   not able to do so.
 * The defer atribute for the minified W3TC scripts is added if the embed type is
   set to defer. Have you also updated query string once the files were minified?
   
   Thanks!
 *  Thread Starter [Jamie Burchell](https://wordpress.org/support/users/jamieburchell/)
 * (@jamieburchell)
 * [6 months ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18689666)
 * I just disabled all plugins except Gravity Forms, Gravity Forms reCAPTCHA and
   W3TC. Only enabled minify. Cleared all caches and reset to a default theme.
 * Minify enabled:
 *     ```wp-block-code
       <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=X&amp;ver=2.0.2" id="gforms_recaptcha_recaptcha-js" defer="defer" data-wp-strategy="defer"></script><script src="https://example.local.test/app/cache/minify/e2eea.js"></script>
       ```
   
 * Minify disabled:
 *     ```wp-block-code
       <script type="text/javascript" src="https://www.google.com/recaptcha/api.js?render=X&amp;ver=2.0.2" id="gforms_recaptcha_recaptcha-js" defer="defer" data-wp-strategy="defer"></script><script type="text/javascript" src="https://example.local.test/app/plugins/gravityformsrecaptcha/js/frontend.min.js?ver=2.0.2" id="gforms_recaptcha_frontend-js" defer="defer" data-wp-strategy="defer"></script>
       ```
   
 * I’m stumped as to why it’s getting stripped out.
 *  Thread Starter [Jamie Burchell](https://wordpress.org/support/users/jamieburchell/)
 * (@jamieburchell)
 * [6 months ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18689706)
 * Think I found the cause [@vmarko](https://wordpress.org/support/users/vmarko/)
 * [This regex](https://github.com/BoldGrid/w3-total-cache/blob/e60b7186dd259979b41db03856566c0230975d0c/Minify_AutoJs.php#L287)
   doesn’t match the string `defer="defer"`. I’ve opened a [Github issue](https://github.com/BoldGrid/w3-total-cache/issues/1226).
 *  Plugin Contributor [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * (@vmarko)
 * [6 months ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18694311)
 * Hey [@jamieburchell](https://wordpress.org/support/users/jamieburchell/)
 * Thank you for submitting the GH issue. the Dev team will take a look at it.
   Pelase
   make sure you follow the progress of the issue.Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Defer attribute on scripts being removed?’ is closed to new replies.

 * ![](https://ps.w.org/w3-total-cache/assets/icon-256x256.png?rev=1041806)
 * [W3 Total Cache](https://wordpress.org/plugins/w3-total-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/w3-total-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/w3-total-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/w3-total-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/w3-total-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/w3-total-cache/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [Marko Vasiljevic](https://wordpress.org/support/users/vmarko/)
 * Last activity: [6 months ago](https://wordpress.org/support/topic/defer-attribute-on-scripts-being-removed/#post-18694311)
 * Status: resolved