| @@ -98,8 +98,14 @@ | ||
| 98 | 98 | // Delay applies a transform that's mutually exclusive with |
| 99 | 99 | // plain defer — when both are on, delay wins (the bootstrap |
| 100 | 100 | // will re-attach as a regular <script> on interaction). |
| 101 | 101 | add_filter( 'script_loader_tag', array( Minify_Filters::class, 'delay_script_tag' ), 30, 3 ); |
| 102 | + // Smart Delay: a delayed handle's before/after snippets park with | |
| 103 | + // it, or the inline consumer would run at parse time against a | |
| 104 | + // global that now arrives on first interaction. This filter fires | |
| 105 | + // for every inline script WordPress prints, so it also covers | |
| 106 | + // pages the cache buffer never filters. | |
| 107 | + add_filter( 'wp_inline_script_attributes', array( Minify_Filters::class, 'park_smart_inline' ), 30, 2 ); | |
| 102 | 108 | add_action( 'wp_footer', array( Minify_Filters::class, 'print_delay_bootstrap' ), 1000 ); |
| 103 | 109 | // script_loader_tag only fires for wp_enqueue_script()'d assets. |
| 104 | 110 | // Analytics / pixel / chat-widget tags printed straight into |
| 105 | 111 | // wp_head bypass it, and those are usually the heaviest scripts |
| @@ -111,8 +117,27 @@ | ||
| 111 | 117 | // The vendors' own install snippets are INLINE (no src at all), |
| 112 | 118 | // so the src sweep above never sees them; this one parks an |
| 113 | 119 | // inline body that names a known third-party host. |
| 114 | 120 | add_filter( 'xspeed_cache_final_html', array( Minify_Filters::class, 'delay_inline_snippets' ), 21 ); |
| 121 | + } | |
| 122 | + | |
| 123 | + // Everything above honors data-no-optimize / data-no-minify, but | |
| 124 | + // only sees markers stamped before priority 30. Borlabs Cookie | |
| 125 | + // stamps at 100, so its consent config was minified AND delayed | |
| 126 | + // despite carrying both markers. Snapshot the tag before our | |
| 127 | + // transforms (9) and hand the original back if a marker turns up | |
| 128 | + // after them (1000, past Borlabs' own 100 and 999). Registered | |
| 129 | + // whenever any of the three is on, | |
| 130 | + // since each one is individually enough to damage a marked | |
| 131 | + // script. (#469) | |
| 132 | + if ( ! empty( $opts['minify_js'] ) || ! empty( $opts['defer_js'] ) || ! empty( $opts['delay_js'] ) ) { | |
| 133 | + add_filter( 'script_loader_tag', array( Minify_Filters::class, 'snapshot_tag' ), 9, 3 ); | |
| 134 | + add_filter( | |
| 135 | + 'script_loader_tag', | |
| 136 | + array( Minify_Filters::class, 'revert_late_marked_tag' ), | |
| 137 | + Minify_Filters::late_opt_out_priority(), | |
| 138 | + 3 | |
| 139 | + ); | |
| 115 | 140 | } |
| 116 | 141 | if ( ! empty( $opts['async_css'] ) ) { |
| 117 | 142 | add_filter( 'style_loader_tag', array( Minify_Filters::class, 'async_style_tag' ), 20, 2 ); |
| 118 | 143 | // style_loader_tag only fires for wp_enqueue_style()'d sheets. |