Nov 23, 2026
2 Views

Laravel Website Speed Optimization: 12 Fixes That Actually Work

Written by

Quick answer: To speed up a Laravel website, cache config, routes and views, enable OPcache, fix N+1 queries with eager loading, move slow tasks to queues, use Redis for cache and sessions, and serve minified assets through a CDN. Then compress images and lazy-load anything below the fold.

Laravel makes building a web app fast, but a fast build doesn’t mean a fast website. Many Laravel sites go live in development mode, run hundreds of database queries per page, and load full-size images and unminified JavaScript. The result is a slow server response, poor Core Web Vitals and visitors who leave before the page loads. The good news is that most Laravel speed problems come from the same small list of causes. This guide walks through 12 practical fixes, in the order we usually apply them, from server-side caching to front-end assets.

Why Is My Laravel Website Slow?

Most slow Laravel sites have one or more of these problems:

ProblemWhat It CausesWhere It Shows
No config/route/view cachingLaravel rebuilds the same data on every requestHigh TTFB
Debug mode on in productionExtra logging and memory useSlow responses, security risk
N+1 database queriesHundreds of queries for one pageSlow server response
Heavy work during the requestEmails, PDFs and API calls block the pageLong wait after form submits
File-based cache and sessionsSlow disk reads under trafficSlow pages at peak hours
Unoptimized CSS, JS and imagesLarge downloads in the browserPoor LCP, INP and CLS

The first four are back-end problems that make your Time to First Byte high. The last one is a front-end problem that hurts Core Web Vitals. A complete laravel performance optimization plan has to fix both.

Which Server-Side Fixes Speed Up Laravel the Most?

1. Cache Config, Routes, Views and Events

By default, Laravel reads config files and registers routes on every request. In production, cache them once:

bash

php artisan optimize

In recent Laravel versions, this one command caches config, events, routes and views. Run it as part of every deployment. If you change a .env value or a config file, run it again, because the cached version is what Laravel uses.

2. Turn Off Debug Mode in Production

In your production .env file, set:

APP_ENV=production
APP_DEBUG=false

Debug mode adds overhead and can expose sensitive details in error pages, so it should never be on for a live site.

3. Optimize the Composer Autoloader

Install dependencies without dev packages and with an optimized class map:

bash

composer install --optimize-autoloader --no-dev

This helps PHP find classes faster and keeps testing and debugging packages off your server.

4. Enable and Tune OPcache

OPcache stores compiled PHP code in memory, so PHP doesn’t have to read and compile your files on every request. Make sure it is enabled in php.ini, and in production you can set opcache.validate_timestamps=0, then reset OPcache (or reload PHP-FPM) after each deployment.

5. Fix N+1 Queries with Eager Loading

This is the most common Laravel speed problem. If you load 50 posts and then call $post->author in a loop, Laravel can run 51 queries instead of 2.

php

// Slow: one extra query for every post
$posts = Post::all();

// Fast: loads authors in one extra query
$posts = Post::with('author')->get();

Laravel can also warn you about this during development. Add Model::preventLazyLoading(! app()->isProduction()); in a service provider, and it will throw an error whenever a relationship is lazy-loaded.

6. Add the Right Database Indexes

Any column you filter, sort or join on often, like user_id, status or created_at, should usually have an index. Without one, the database scans the whole table. Also select only the columns you need instead of SELECT * on large tables.

7. Move Slow Work to Queues

Sending emails, generating PDFs, resizing images and calling third-party APIs should not happen while the visitor waits. Push them to a queue:

php

SendWelcomeEmail::dispatch($user);

Then run a queue worker (managed by Supervisor or a similar tool) so these jobs are processed in the background.

8. Use Redis for Cache and Sessions

File-based cache and sessions are fine for small sites, but they slow down under traffic. Redis keeps data in memory and is much faster:

CACHE_STORE=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

In older Laravel versions the cache variable is CACHE_DRIVER instead of CACHE_STORE. Then cache expensive queries:

php

$categories = Cache::remember('categories', 3600, fn () => Category::all());

9. Consider Laravel Octane for High Traffic

Laravel Octane keeps your app loaded in memory between requests, using servers like FrankenPHP, Swoole or RoadRunner. It can make a big difference on busy apps, but test it carefully, because code that stores state in static properties or singletons can behave differently.

Which Front-End Fixes Improve Core Web Vitals?

A fast server only fixes half the problem. The browser still has to download and render everything.

10. Bundle and Minify CSS and JavaScript

Build your assets for production with Vite (npm run build), which minifies files and adds version hashes for long-term caching. Also remove CSS and JS that a page doesn’t use, and defer non-critical scripts. Our guide on how to optimize JavaScript and CSS goes deeper into this.

11. Optimize and Lazy-Load Images

Convert images to WebP, resize them to the size they are shown at, and lazy-load anything below the fold with loading="lazy". Always set width and height on images to prevent layout shift. If you use a CDN, see how to render WebP images with CDN or Cloudflare.

12. Serve Static Files Through a CDN and Enable Compression

Serve CSS, JS, images and fonts from a CDN, enable Gzip or Brotli compression on your web server, and set long cache headers for versioned assets.

Laravel Speed Optimization Checklist

FixCommand or SettingMain Impact
Cache config, routes, viewsphp artisan optimizeTTFB
Debug offAPP_DEBUG=falseTTFB, security
Optimized autoloadercomposer install --optimize-autoloader --no-devTTFB
OPcacheEnabled in php.iniTTFB
Eager loading->with('relation')Database time
IndexesMigration ->index()Database time
QueuesJob::dispatch()Response time
RedisCACHE_STORE=redisCache and session speed
Asset buildnpm run buildLCP, INP
ImagesWebP, lazy-load, dimensionsLCP, CLS
CDN and compressionCDN + Brotli/GzipLCP

Can a Laravel Speed Optimization Package Do This Automatically?

The server-side fixes above (caching, queries, queues, Redis) need a developer, because they depend on how your app is built. Front-end optimization is different. Minifying and combining CSS and JS, generating critical CSS, converting images to WebP, lazy-loading and delaying scripts are the same work on every site, and they are easy to get wrong by hand.

This is where a laravel speed optimization package helps. W3Speedster’s Laravel library handles front-end optimization, caching and Core Web Vitals improvements on top of your existing app, without you rewriting your Blade templates. Your developers fix the back end, and the package takes care of what the browser loads. You can learn more about Laravel website speed optimization with W3Speedster or try it from the free downloads page.

How Do You Check If Your Laravel Site Is Faster?

  1. Test before and after with Google PageSpeed Insights, on mobile and desktop.
  2. Watch TTFB to measure the server-side fixes. If TTFB is still high, see our guide on what TTFB is and how to reduce it.
  3. Check Core Web Vitals (LCP, INP and CLS) for the front-end fixes. Our Core Web Vitals optimization guide explains each metric.
  4. Count queries in development with Laravel Debugbar or Telescope, and make sure the number drops after eager loading.

Conclusion

Laravel website speed optimization doesn’t need a full rebuild. Start with the quick wins: run php artisan optimize, turn off debug mode, enable OPcache and fix N+1 queries. Then move slow work to queues, switch cache and sessions to Redis, and clean up your front-end assets and images. Test before and after each step so you know what actually helped. Fix the server, fix the browser, and your Laravel site will feel fast for real users, not just on a test score.


Frequently Asked Questions

1. How do I speed up my Laravel website?
Cache config, routes and views, enable OPcache, fix N+1 queries, use queues and Redis, and minify assets and optimize images.

2. What does php artisan optimize do?
In recent Laravel versions it caches config, events, routes and views in one command, so Laravel doesn’t rebuild them on every request.

3. Should APP_DEBUG be true in production?
No. Set APP_DEBUG=false in production. Debug mode slows the app down and can expose sensitive information.

4. What is the N+1 query problem in Laravel?
It happens when a page runs one query for a list and then one more query for each item’s relationship. Eager loading with with() fixes it.

5. Is Redis better than file cache for Laravel?
For busy sites, yes. Redis keeps data in memory, so cache and session reads are much faster than reading files from disk.

6. Does Laravel Octane make my site faster?
It can, especially on high-traffic apps, because the app stays loaded in memory. Test it carefully first, because shared state can cause bugs.

7. How does OPcache help Laravel?
OPcache stores compiled PHP code in memory, so PHP doesn’t recompile your files on every request.

8. Why are queues important for Laravel performance?
They move slow tasks like emails and API calls to the background, so visitors don’t wait for them.

9. How do I improve Core Web Vitals on a Laravel site?
Minify and defer CSS and JS, convert images to WebP, lazy-load below-the-fold content, set image dimensions and use a CDN.

10. Is there a Laravel speed optimization package?
Yes. W3Speedster offers a Laravel optimization library that handles front-end optimization, caching and Core Web Vitals improvements.

11. How do I measure Laravel performance?
Use PageSpeed Insights for TTFB and Core Web Vitals, and Laravel Debugbar or Telescope in development to count queries and find slow code.

12. How often should I run php artisan optimize?
On every deployment, and again whenever you change config or .env values.

Article Categories:
Fashion