Performance: WooCommerce hooks for customization
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by controlling when and how WooCommerce features are added or modified in the page rendering process.
<?php add_action('woocommerce_before_single_product', 'custom_function'); function custom_function() { echo '<div>Optimized content</div>'; } ?>
<?php add_action('woocommerce_before_single_product', 'custom_function'); function custom_function() { for ($i=0; $i<1000; $i++) { echo '<div>Extra content</div>'; } } ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy HTML in hooks | Large DOM increase | Multiple reflows | High paint cost | [X] Bad |
| Minimal HTML in hooks | Small DOM increase | Single reflow | Low paint cost | [OK] Good |
| Unconditional asset enqueue | No DOM change | No reflows | Blocks rendering | [X] Bad |
| Conditional asset enqueue | No DOM change | No reflows | Non-blocking | [OK] Good |