3
8 Comments

Any tips for improving Laravel page load speed?

Hey IH,

I run a site and blog at employbl dot com. It's one of my goals this year to grow traffic to 20k+ users per month (I'm at about 1-2k/month now) and SEO and my blog is going to be a big part of that. Employbl is a Laravel site and the blog is powered by Laravel Nova. I ran my blog through some speed testers (https://tools.pingdom.com/ and Google Search Console) and it leaves a lot to be desired. Has anyone successfully optimized page load speed for Laravel apps? Any hints?

These are the resources I found online. Other articles you've written or found helpful about Laravel page load speed or page load speed in general helpful

(This might be better question for laracasts forum or reddit or something but I really like the IH community so asking here first..)

  1. 4

    Have laravel running loads of production systems and little issues with performance.

    Delays are more likely in database or server performance.

    Redis/memcached or similar caching can reduce DB requests and boost performance.
    Latest PHP versions a little faster than older versions, miles ahead of the old 5.x days.
    Caching config files, optimising autoload etc can all help.
    Make sure opcache running and efficient on cache hits.

    If you are on a shared hosting provider, get a $10 SSD backed cloud server and will get a massive boost, just need to manage and configure the server a little.
    Nginx works faster than apache in most cases for laravel.

  2. 2

    How many database queries are you doing on page load? The way to make your site faster is by using an in-memory cache. Disk access is slow (mysql, postgress), memory access is much faster.

    You can also generate your dynamically generated pages and cache the result using something like varnish.

    The first thing you should do is setup caching if you're not already doing it. The second thing is to make sure your're not loading any assets (css, javascript) that aren't needed.

  3. 2

    Hey @connor11528, I'm using laravel for one of my sites which receives around the same amount of traffic, I have found this package really useful in improving speeds significantly, it basically minifies / compresses HTML the same way you would minify JS or CSS and this has a great impact as pages load faster, you can check it out here:

    https://github.com/HTMLMin/Laravel-HTMLMin

    Response cache will also improve your speeds as long as you make sure to have a way to clear the cache e.g when a blog is updated or new one create, or updated then the cache is cleared, or even having an interval for it to clear and re-cache.

    You can also integrate Cloudflare, this will also assist in caching and reducing the amout of load on your server(s) as Cloudflare will serve up all the front end content to the users e.g css / js files which are frequently used.

    Hope that helps!

  4. 2

    Hi Connor, I recommend you install the laravel debug bar (https://packagist.org/packages/barryvdh/laravel-debugbar). It's really useful for identifying slow queries and other issues. Just becareful if you intend to run it on a production environment -make sure you condition to only display for a certain user. Eager loading on your relationships can have a massive performance improvement. You could also compress your assets using brotli npm package.

  5. 2

    The most common causes are:

    • 3rd party requests
    • large asset sizes
    • bloated front-end SPA
    • excessive or inefficient DB queries

    The one most important link you could have shared with us was the URL of the page (or type of page) that's loading too slowly! We can't see the DB queries you're making, but the first three factors are pretty easy to diagnose by looking in the browser dev tools.

    1. 2

      Oh for sure. This is a blog post on my site that I’m trying to optimize, or even the homepage https://employbl.com/blog/laravel-vue-tailwindcss-single-page-application-spa

  6. 1

    Hi Connor, do you use a cache system on the app using Reddit, I think this can help a lot

Trending on Indie Hackers
I talked to 8 SaaS founders, these are the most common SaaS tools they use 20 comments What are your cold outreach conversion rates? Top 3 Metrics And Benchmarks To Track 19 comments How I Sourced 60% of Customers From Linkedin, Organically 12 comments Hero Section Copywriting Framework that Converts 3x 12 comments Promptzone - first-of-its-kind social media platform dedicated to all things AI. 8 comments How to create a rating system with Tailwind CSS and Alpinejs 7 comments