Fixing Core Web Vitals on Legacy PHP Sites

Legacy PHP sites can still pass Core Web Vitals. I share the performance fixes that moved the needle on older client websites.

Fixing Core Web Vitals on Legacy PHP Sites

If you are working on improving Core Web Vitals on legacy PHP sites, these are the details I wish had been documented earlier. Legacy PHP sites can still pass Core Web Vitals. I share the performance fixes that moved the needle on older client websites.

Measure Before Optimising Randomly

Legacy PHP sites can still pass Core Web Vitals. I share the performance fixes that moved the needle on older client websites.

  • image compression — applied directly to improving Core Web Vitals on legacy PHP sites.
  • defer JS — applied directly to improving Core Web Vitals on legacy PHP sites.
  • critical CSS — applied directly to improving Core Web Vitals on legacy PHP sites.
  • caching headers — applied directly to improving Core Web Vitals on legacy PHP sites.

Putting It Together

For Fixing Core Web Vitals on Legacy PHP Sites, I kept the implementation narrow: image compression, defer JS, critical CSS, caching headers, and font loading. Every decision tied back to that scope instead of expanding into unrelated admin features.

Fix the Largest Contentful Paint First

Representative code from the implementation — simplified for readability, but structurally what I deploy.

Dynamic SEO head tags in PHP

<title><?= htmlspecialchars($meta_title) ?></title>
<meta name="description" content="<?= htmlspecialchars($meta_description) ?>">
<meta property="og:title" content="<?= htmlspecialchars($meta_title) ?>">
<meta property="og:description" content="<?= htmlspecialchars($meta_description) ?>">
<meta property="og:image" content="<?= htmlspecialchars($base_url . 'uploads/' . rawurlencode($og_image)) ?>">

Strict input validation at the service boundary

<?php
declare(strict_types=1);

final class RecordService
{
    public function create(array $input): array
    {
        $title = trim($input['title'] ?? '');
        if ($title === '' || strlen($title) > 180) {
            throw new InvalidArgumentException('Invalid title.');
        }
        $stmt = $this->db->prepare('INSERT INTO records (title) VALUES (?)');
        $stmt->bind_param('s', $title);
        $stmt->execute();
        return ['id' => $stmt->insert_id];
    }
}

Where This Approach Paid Off

Shipping improving Core Web Vitals on legacy PHP sites cleanly meant the next developer could extend it without untangling hidden coupling.

If I repeated this, I would write the regression checks earlier — especially around the failure paths users hit once, not the happy path.

Closing Thoughts

  • Start with the exact problem statement for improving Core Web Vitals on legacy PHP sites — one sentence, no buzzwords.
  • Prioritise image compression before polishing secondary UI details.
  • Validate defer JS under realistic data volume, not demo rows.