Performance: Enqueuing styles and scripts
HIGH IMPACT
This affects page load speed by controlling when and how CSS and JavaScript files load, impacting render blocking and bundle size.
<?php
function theme_enqueue_assets() {
wp_enqueue_style('theme-style', get_stylesheet_uri());
wp_enqueue_script('theme-script', get_template_directory_uri() . '/script.js', [], null, true);
}
add_action('wp_enqueue_scripts', 'theme_enqueue_assets');<?php // Directly adding styles and scripts in header.php ?><link rel="stylesheet" href="style.css"> <script src="script.js"></script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Directly adding <link> and <script> tags in header | Minimal DOM nodes added | Multiple reflows due to blocking | High paint cost due to delayed styles | [X] Bad |
| Using wp_enqueue_style and wp_enqueue_script with footer loading | Minimal DOM nodes added | Single reflow after styles load | Lower paint cost, faster LCP | [OK] Good |