Performance: Theme from scratch setup
HIGH IMPACT
This affects the initial page load speed and rendering performance by controlling how much code and assets are loaded and how efficiently the theme renders content.
<?php
// functions.php
function theme_scripts() {
if (is_single()) {
wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array(), null, true);
}
wp_enqueue_style('style', get_stylesheet_uri(), array(), null, 'all');
}
add_action('wp_enqueue_scripts', 'theme_scripts');
// header.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<header>
<h1><?php bloginfo('name'); ?></h1>
</header>
<main>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
</article>
<?php endwhile; endif; ?>
<?php the_posts_pagination(); ?>
</main>
<?php wp_footer(); ?>
</body>
</html><?php
// functions.php
function theme_scripts() {
wp_enqueue_style('style', get_stylesheet_uri());
wp_enqueue_script('jquery');
wp_enqueue_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'theme_scripts');
// header.php
<!DOCTYPE html>
<html>
<head>
<?php wp_head(); ?>
</head>
<body>
<header>
<h1><?php bloginfo('name'); ?></h1>
</header>
<main>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<article>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
<?php endwhile; endif; ?>
</main>
<?php wp_footer(); ?>
</body>
</html>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Loads all scripts and full content on every page | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Loads scripts conditionally and uses excerpts with pagination | Medium (fewer nodes) | Single reflow | Lower paint cost | [OK] Good |