| @@ -75,8 +75,15 @@ | ||
| 75 | 75 | add_filter( 'style_loader_src', array( __CLASS__, 'rewrite_style' ), 10, 2 ); |
| 76 | 76 | } |
| 77 | 77 | if ( ! empty( $opts['minify_js'] ) ) { |
| 78 | 78 | add_filter( 'script_loader_src', array( __CLASS__, 'rewrite_script' ), 10, 2 ); |
| 79 | + // The src rewrite above runs before any plugin's own | |
| 80 | + // `script_loader_tag` filter can stamp data-no-minify / | |
| 81 | + // data-no-optimize onto the tag, so the marker arrives too late | |
| 82 | + // to prevent it. Priority 15: after third-party tag filters at | |
| 83 | + // the default 10 have printed their markers, before our defer | |
| 84 | + // (20) and delay (30) look at the tag. (#456) | |
| 85 | + add_filter( 'script_loader_tag', array( Minify_Filters::class, 'restore_marked_script_src' ), 15, 3 ); | |
| 79 | 86 | } |
| 80 | 87 | |
| 81 | 88 | // Phase 4.1a — filter-only "smarter minifier" features. Each is |
| 82 | 89 | // gated on its own toggle so users can enable any subset. |
| @@ -105,8 +112,27 @@ | ||
| 105 | 112 | // so the src sweep above never sees them; this one parks an |
| 106 | 113 | // inline body that names a known third-party host. |
| 107 | 114 | add_filter( 'xspeed_cache_final_html', array( Minify_Filters::class, 'delay_inline_snippets' ), 21 ); |
| 108 | 115 | } |
| 116 | + | |
| 117 | + // Everything above honors data-no-optimize / data-no-minify, but | |
| 118 | + // only sees markers stamped before priority 30. Borlabs Cookie | |
| 119 | + // stamps at 100, so its consent config was minified AND delayed | |
| 120 | + // despite carrying both markers. Snapshot the tag before our | |
| 121 | + // transforms (9) and hand the original back if a marker turns up | |
| 122 | + // after them (1000, past Borlabs' own 100 and 999). Registered | |
| 123 | + // whenever any of the three is on, | |
| 124 | + // since each one is individually enough to damage a marked | |
| 125 | + // script. (#469) | |
| 126 | + if ( ! empty( $opts['minify_js'] ) || ! empty( $opts['defer_js'] ) || ! empty( $opts['delay_js'] ) ) { | |
| 127 | + add_filter( 'script_loader_tag', array( Minify_Filters::class, 'snapshot_tag' ), 9, 3 ); | |
| 128 | + add_filter( | |
| 129 | + 'script_loader_tag', | |
| 130 | + array( Minify_Filters::class, 'revert_late_marked_tag' ), | |
| 131 | + Minify_Filters::late_opt_out_priority(), | |
| 132 | + 3 | |
| 133 | + ); | |
| 134 | + } | |
| 109 | 135 | if ( ! empty( $opts['async_css'] ) ) { |
| 110 | 136 | add_filter( 'style_loader_tag', array( Minify_Filters::class, 'async_style_tag' ), 20, 2 ); |
| 111 | 137 | // style_loader_tag only fires for wp_enqueue_style()'d sheets. |
| 112 | 138 | // Themes print Google/Bunny/Typekit font CSS as literal <link> |
| @@ -432,8 +458,14 @@ | ||
| 432 | 458 | } |
| 433 | 459 | list( , $open, $body, $close ) = $parts; |
| 434 | 460 | |
| 435 | 461 | if ( '' === trim( $body ) ) { |
| 462 | + return $block; | |
| 463 | + } | |
| 464 | + | |
| 465 | + // The tag asked to be left alone (data-no-optimize / data-no-minify — | |
| 466 | + // the convention consent managers print on their config scripts). (#456) | |
| 467 | + if ( Minify_Filters::tag_opts_out( $open ) ) { | |
| 436 | 468 | return $block; |
| 437 | 469 | } |
| 438 | 470 | |
| 439 | 471 | // Refuse a body that is already structurally broken. balanced() only |