Laravel is a PHP-based open-source framework that follows an MVC architectural pattern and modular packaging system. RabbitLoader can be used to improve PageSpeed Insights and core web vitals for the Laravel websites.
The RabbitLoader Laravel Package is available via Composer and it is pretty easy to install. Navigate to the root directory of the website first (where you already have the website’s composer.json file. To install the package, run the below command-
composer require rabbit-loader/laravel
After successful installation of the package, activate the package using the below command-
php artisan vendor:publish --provider='RabbitLoader\Laravel\RLServiceProvider'
In the app/Http/Kernel.php file, add the RabbitLoader middleware.
protected $middleware = [
The package requires a license key to function. The license key for the website can be obtained when you add a website.
Navigate to the “My Websites” section on the RabbitLoader console and click on the “Add New Website” button. Please refer to the below screenshot for reference –
Please note that if you lose the license key, you can not get it again as this is a one-time process. To issue a license key again, you need to first delete the website from the main menu Action->Delete.
The license key should be saved in the ‘.env’ file of the Laravel app. The .env file should be at the root of the website (at the same place where the
composer.json) file is available. Append this towards the end of the .env file and replace the license value with the one you got above.
RABBIT_LOADER_LICENSE_KEY="license key goes here"
There are a few ways page optimization can be controlled.
The package also has multiple ways to exclude specific pages from being optimized and cached by RabbitLoader. After installing the package, go to the config file located at /config/rabbitloader.php and adjust these values to meet your needs-
//skip caching if path starts with admin
'skipPaths' => ['/admin*'],
//skip caching if a cookie is found with name cookie1
'skipCookies' => ['cookie1'],
When an existing page’s content is updated from the admin section or by other means, a purging of the cached content is required to reflect the updated changes.
#in the admin section
$liceseKey = config('rabbitloader.licenseKey', '');
$cacheDir = config('rabbitloader.cacheDir', '');
$rlSDK = new RabbitLoader\SDK\RabbitLoader($licenseKey, $cacheDir);
$urlModified = 'https://mywebsite.com/modified-page-slug/';
#if home page needs to be purged too, then-
When updating an existing CSS/JS file or an image, make sure that you use some kind of versioning in the resource path. Since the existing files are already cached on the edge servers, modifying the file on the hosting server may introduce a delay in reflecting those for the website visitors.
Below is an example where you see
'?v=1.2' appended as a GET parameter to a CSS file. When you update this file, simply change the version to
'?v=1.3' or anything of that sort that ignores the previous version of the CSS file when serving the page to visitors.
<link rel="stylesheet" href="https://mywebsite.com/assets/css/theme.css?v=1.2" />