Laravel Performance Optimization: How I Cut Page Loads from 4 Seconds to 400ms
A field-tested checklist for making Laravel applications fast: query fixes, caching layers, asset strategy and the Core Web Vitals wins that actually move rankings.
Muhammad Umair
Full Stack Web Developer
3 min read
On this page
Most slow Laravel applications are not slow because of PHP. They are slow because of a handful of very fixable habits: queries that run in loops, pages that rebuild the same data on every request, and front-ends that ship more JavaScript than content. This is the exact process I use on client projects to take a page from a four-second load to under half a second.
1. Kill the N+1 queries first
Before touching any caching layer, open the slowest page with a query logger and count the queries. If a page lists 20 projects and runs 61 queries, you have an N+1 problem — each row is lazily loading its relations.
// Before: 1 + 20 + 20 queries
$projects = Project::latest()->take(20)->get();
// After: 3 queries
$projects = Project::with(['category', 'tags'])->latest()->take(20)->get();
In production I go one step further and enable Model::preventLazyLoading() in non-production environments, so any accidental lazy load fails loudly during development instead of silently stacking queries for real visitors.
2. Add the right indexes, not more indexes
Every column that appears in a where, order by or join on a hot path deserves a look. Composite indexes should match your query shape: a feed filtered by is_published and sorted by published_at wants one index covering both, in that order. Measure with EXPLAIN — if MySQL reports a full table scan on a table with more than a few thousand rows, fix it before adding servers.
3. Cache in layers
- Query cache: expensive aggregates (dashboard counts, related-content lookups) go into the cache for minutes or hours, keyed by the data they depend on.
- Fragment cache: rendered sections that rarely change — footers, menus, sidebars — are cached as HTML.
- Full-page cache: for guests, whole responses can be cached and served without booting most of the framework.
The golden rule: every cache needs an owner that clears it. In this portfolio’s CMS, every admin save flushes exactly the keys it affects, so the site is always fresh without ever rebuilding everything.
4. Ship less front-end
Core Web Vitals are mostly won in the browser. The checklist that pays off every time:
- Serve images in modern formats with explicit aspect ratios so the layout never shifts.
- Mark the hero image with
fetchpriority="high"and lazy-load everything below the fold. - Bundle with Vite, let HTTP/2 do its job, and defer every script that is not needed for first paint.
- Preconnect to your font host and load only the weights you actually use.
5. Measure like Google does
Lighthouse in an incognito window is a fine start, but field data wins arguments. PageSpeed Insights shows real-user Core Web Vitals once your site has traffic; until then, test on a throttled mobile profile because that is where the 2.5s LCP budget actually bites.
Performance is a feature you ship once and defend forever. If your Laravel application needs this treatment, my Technical SEO & Speed Optimization service exists for exactly that — or tell me about your project and I will take a look.
Frequently asked questions
Aim for a server response (TTFB) under 200ms for cached pages and under 500ms for dynamic pages. Combined with optimized assets, that keeps Largest Contentful Paint comfortably inside Google’s 2.5 second threshold.
No — the trick is caching in layers. Cache full responses only for guests, cache queries and computed fragments for everyone, and tag or key caches so updates clear exactly what changed.
Enable the slow query log in MySQL, use Laravel Debugbar or Telescope in development, and watch for N+1 patterns — they are the single most common cause of slow Laravel pages.
Written by
Muhammad Umair
Full Stack Web Developer specialising in Laravel, Livewire and Next.js. I write about building fast, maintainable web applications.
Need help with a project like this?
I build fast, secure web applications with Laravel, Livewire and Next.js.
Get new articles in your inbox
Practical tips on Laravel, Next.js and building fast web apps. No spam — unsubscribe anytime.