From 5eee65faaa12eb566c2539b2ff1a708802ba5a03 Mon Sep 17 00:00:00 2001 From: Darren Wiebe Date: Sat, 28 Jun 2025 19:02:11 +0000 Subject: [PATCH] Add support to use a CDN along with basset. Use an external CDN together with Basset --- readme.md | 1 + src/Helpers/FileOutput.php | 2 +- src/config/backpack/basset.php | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 210123e..1560386 100644 --- a/readme.md +++ b/readme.md @@ -174,6 +174,7 @@ Take a look at [the config file](https://github.com/Laravel-Backpack/basset/blob - enable/disable dev mode using `BASSET_DEV_MODE=false` - this will force Basset to internalize assets even on localhost - change the disk where assets get internalized using `BASSET_DISK=yourdiskname` - disable the cache map using `BASSET_CACHE_MAP=false` (needed on serverless like Laravel Vapor) +- use an external CDN together with Basset using `BASSET_CDN_URL=https://yoursite.examplecdnprovider` ## Deployment diff --git a/src/Helpers/FileOutput.php b/src/Helpers/FileOutput.php index 3982227..6b5b2ee 100644 --- a/src/Helpers/FileOutput.php +++ b/src/Helpers/FileOutput.php @@ -76,7 +76,7 @@ public function assetPath(string $path): string $asset = $asset->after('//')->after('/')->start('/'); } - return $asset->value(); + return config('backpack.basset.cdn_url') . $asset->value(); } /** diff --git a/src/config/backpack/basset.php b/src/config/backpack/basset.php index f76853a..2fa9cf8 100644 --- a/src/config/backpack/basset.php +++ b/src/config/backpack/basset.php @@ -25,4 +25,8 @@ // use relative path 'relative_paths' => env('BASSET_RELATIVE_PATHS', true), + + // Populate this to use a CDN like AWS Cloudfront with basset. + // Example: https://example.cloudfront.net + 'cdn_url' => env('BASSET_CDN_URL', ''), ];