Laravel optimization techniques
When you need fast performance, there are many things you can do to optimize Laravel.
1. Recent version
Make sure you're using a recent version, like Laravel version 11 (in 2024).
Make sure your PHP version is 8.2 or 8.3 (in 2024) as they provide performance and security improvements.
Check a full list of Laravel versions here and a full list of PHP versions here.
2. Artisan commands
To optimize Laravel, add the following command to your deployment.
The files that will be cached, include your configuration, events, routes, and views:
# you likely already runs this, right? to update your database structure php artisan migrate # run optimize command php artisan optimize
Remove all of the cache files with the following command:
php artisan optimize:clear
The optimize command (above) does the following:
php artisan config:cache php artisan event:cache php artisan route:cache php artisan view:cache
Clear the individual caches with the following commands:
php artisan config:clear php artisan event:clear php artisan route:clear php artisan view:clear
3. Optimize database queries
- Look into optimizing your database queries.
- Look into caching values that don't need to be super up-to-date
- Add indexes to make database queries much quicker.
- Use Eager loading where possible.
- Debugbar can be a helpful package during development
4. Minify
Minify css and javascript, using Webpack, Grunt or Vite for example.
5. CDN
Put Cloudflare in front of your site, or use a CDN like Amazon Cloudfront to host the static assets.