Performance: Template parts
MEDIUM IMPACT
Template parts affect page load speed by controlling how reusable sections of a page are loaded and rendered.
<?php
ob_start();
get_template_part('header');
$header_html = ob_get_clean();
echo $header_html;
echo $header_html;
echo $header_html;
?><?php get_template_part('header'); ?> <?php get_template_part('header'); ?> <?php get_template_part('header'); ?>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated get_template_part calls | No extra DOM nodes but slower HTML generation | No direct reflows but delayed HTML delivery | Normal paint cost | [X] Bad |
| Single get_template_part call with output reuse | No extra DOM nodes, faster HTML generation | No reflows, faster HTML delivery | Normal paint cost | [OK] Good |