settings = $settings; $this->exclusions = $exclusions; $this->bloat = new AWVB_Bloat( $settings ); $this->images = new AWVB_Images( $settings ); $this->assets = new AWVB_Assets( $settings ); $this->cache = new AWVB_Cache( $settings ); } /** * Initialize optimizer modules. * * @param AWVB_Loader $loader */ public function init( $loader ) { // Initialize bloat removal (hook-based) $this->bloat->init(); // Initialize browser caching headers $this->cache->init(); // Setup HTML output buffer for assets & images on frontend $loader->add_action( 'template_redirect', $this, 'start_buffer', 1 ); } /** * Starts output buffering on eligible frontend requests. */ public function start_buffer() { if ( $this->exclusions->is_current_request_excluded() ) { return; } if ( is_feed() || is_robots() || is_trackback() ) { return; } ob_start( array( $this, 'process_buffer' ) ); } /** * Buffer callback: parses and optimizes the final HTML document. * * @param string $buffer * @return string */ public function process_buffer( $buffer ) { if ( empty( $buffer ) || false === stripos( $buffer, 'exclusions->is_current_request_excluded() ) { return $buffer; } // 1. Image optimizations (Smart Lazy Loading + LCP protect + CLS dimensions) $buffer = $this->images->process_html( $buffer ); // 2. Asset optimizations (JS defer/delay, fonts, HTML minification) $buffer = $this->assets->process_html( $buffer ); return $buffer; } }