### Install RabbitLoader PHP SDK via Composer Source: https://rabbitloader.com/kb/setting-up-rabbitloader-on-custom-php-website This command installs the RabbitLoader PHP SDK using Composer. Ensure your PHP version is 5.6 or higher. Composer handles dependency management for the SDK. ```bash composer require rabbit-loader/php-sdk ``` -------------------------------- ### Install and Activate RabbitLoader Package Source: https://rabbitloader.com/kb/installing-rabbitloader-on-a-laravel-website Commands to install the RabbitLoader package via Composer and publish the necessary service provider configuration to the Laravel application. ```bash composer require rabbit-loader/laravel php artisan vendor:publish --provider='RabbitLoader\Laravel\RLServiceProvider' ``` -------------------------------- ### Static Asset Versioning and Cache Purging Source: https://rabbitloader.com/kb/installing-rabbitloader-on-a-laravel-website Techniques for cache busting static assets using query parameters and clearing the entire cache directory via command line. ```html ``` ```bash rm /tmp/rabbitloader/* ``` -------------------------------- ### Configure Middleware and Environment Variables Source: https://rabbitloader.com/kb/installing-rabbitloader-on-a-laravel-website Instructions for registering the RabbitLoader middleware in the Kernel and setting the required license key in the .env file. ```php //app/Http/Kernel.php protected $middleware = [ ... \RabbitLoader\Laravel\Process::class ... ] ``` ```text RABBIT_LOADER_LICENSE_KEY="license key goes here" ``` -------------------------------- ### Exclude JS File from Optimization using Page Rule Source: https://rabbitloader.com/kb/enable-disable-defer-loading-of-javascript This example demonstrates how to exclude a specific JavaScript file ('my-imp-script.js') from being optimized or deferred by RabbitLoader using a Page Rule. Multiple file names can be added, separated by a comma. Exercise caution when excluding files, as dependencies on other deferred JS files can cause website breakage. ```html ``` -------------------------------- ### Integrate RabbitLoader SDK in PHP Website Source: https://rabbitloader.com/kb/setting-up-rabbitloader-on-custom-php-website Integrates the RabbitLoader SDK into your PHP website's entry file (e.g., index.php). It requires loading the Composer autoloader, initializing the SDK with your license key and storage directory, and calling the process method before any output. ```php #1 make sure the composer autolaod file is loaded at the top require_once("/vendor/autoload.php"); #2 integrate RabbitLoader $licenseKey = 'YOUR_LICENSE_KEY'; //get your license key from environment variable $storageDir = '/home/usr/cache-disk/rabbitloader'; //full path storage location where cached files will be stored $rlSDK = new RabbitLoader\SDK\RabbitLoader($licenseKey, $storageDir); $rlSDK->process(); #3 important headers header('Content-Type: text/html; charset=utf-8'); #4 remaining code of the website goes after this ... echo "

Hello World!

" ``` -------------------------------- ### Programmatic Cache Invalidation Source: https://rabbitloader.com/kb/installing-rabbitloader-on-a-laravel-website Using the RabbitLoader SDK to trigger a cache purge for specific URLs when content is updated within the application. ```php $liceseKey = config('rabbitloader.licenseKey', ''); $cacheDir = config('rabbitloader.cacheDir', ''); $rlSDK = new RabbitLoader\SDK\RabbitLoader($licenseKey, $cacheDir); $urlModified = 'https://mywebsite.com/modified-page-slug/'; $rlSDK->onContentChange($urlModified); #if home page needs to be purged too, then- $rlSDK->onContentChange('https://mywebsite.com/'); ``` -------------------------------- ### Purge RabbitLoader Cache for Specific URLs Source: https://rabbitloader.com/kb/setting-up-rabbitloader-on-custom-php-website This PHP code demonstrates how to programmatically purge the RabbitLoader cache for specific URLs. It's useful for updating content and ensuring users see the latest version. The `onContentChange` method should be called before the `process()` method. ```php #admin.php #load composer autoload.php and initialize PHP SDK. $urlModified = 'https://mywebsite.com/modified-page-slug/'; $rlSDK->onContentChange($urlModified); #if home page needs to be purged too, then- $rlSDK->onContentChange('https://mywebsite.com/'); ```