PHPackages                             arubacao/asset-cdn - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. arubacao/asset-cdn

ActiveLibrary[File &amp; Storage](/categories/file-storage)

arubacao/asset-cdn
==================

Serve Laravel Assets from a Content Delivery Network (CDN)

0.3.0(1mo ago)110191.8k↓69.3%30[4 issues](https://github.com/arubacao/asset-cdn/issues)[2 PRs](https://github.com/arubacao/asset-cdn/pulls)MITPHPPHP ^8.1CI passing

Since Mar 3Pushed 1w ago5 watchersCompare

[ Source](https://github.com/arubacao/asset-cdn)[ Packagist](https://packagist.org/packages/arubacao/asset-cdn)[ Docs](https://github.com/arubacao/asset-cdn)[ RSS](/packages/arubacao-asset-cdn/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (7)Dependencies (14)Versions (13)Used By (0)

[![](https://raw.githubusercontent.com/arubacao/asset-cdn/master/asset-cdn.png)](https://raw.githubusercontent.com/arubacao/asset-cdn/master/asset-cdn.png)

[![Latest Stable Version](https://camo.githubusercontent.com/35ed6adeb09cc8ffd4cb50fe37aa70b6a461fab035eef987e151c2129c19231a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617275626163616f2f61737365742d63646e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arubacao/asset-cdn)[![GitHub Workflow Status](https://camo.githubusercontent.com/9af032dbb8a246b2f6224f1c6a0ca0d0b0f0410aff66ee1e3d0de2e6a23d0767/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f617275626163616f2f61737365742d63646e2f72756e2d74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/arubacao/asset-cdn/actions/workflows/run-tests.yml)[![Codecov](https://camo.githubusercontent.com/aaac5fc2a84011bdab36df7b2b63cb33e98b1eb44efa3bb0777f2781b9c28cc1/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f617275626163616f2f61737365742d63646e2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/gh/arubacao/asset-cdn)[![Total Downloads](https://camo.githubusercontent.com/772fb8c5b845d1391347f90480795031067a751468e8f58754799b4ea05cb1f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617275626163616f2f61737365742d63646e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arubacao/asset-cdn)

**Serve Laravel Assets from a Content Delivery Network (CDN)**

Introduction
------------

[](#introduction)

This package lets you **push**, **sync**, **delete** and **serve** assets to/from a CDN of your choice e.g. AWS Cloudfront.
It adds helper methods **`mix_cdn()`** and **`asset_cdn()`**.

#### Simple Illustration

[](#simple-illustration)

```
>>> env('USE_CDN')
=> true
```

```
$ php artisan asset-cdn:sync
```

```
// head.blade.php

```

```

```

Installation
------------

[](#installation)

Install this package via composer:

```
$ composer require arubacao/asset-cdn
```

The service provider is auto-discovered by supported Laravel versions.

Notes:

- `arubacao/asset-cdn` supports Laravel `9`, `10`, `11`, `12`, and `13`.
- The minimum supported PHP version is `8.1`; Laravel `13` requires PHP `8.3` or newer.
- The CI matrix tests the supported Laravel versions with their compatible PHP, Testbench, and PHPUnit versions.

Configuration
-------------

[](#configuration)

#### 1. Configure Filesystem

[](#1-configure-filesystem)

*Only required if you plan to manage your assets via the provided commands: `asset-cdn:push`, `asset-cdn:sync`, `asset-cdn:empty`*

`arubacao/asset-cdn` utilizes [Laravel's Filesystem](https://laravel.com/docs/filesystem) to **push**, **sync**, **delete** assets to/from the CDN of your choice. Therefore, you have to configure and define a filesystem specific for CDN purposes. Please follow the [official documentation](https://laravel.com/docs/filesystem).

If you plan to use AWS S3/Cloudfront you can use this configuration:

```
// config/filesystems.php

'asset-cdn' => [
    'driver' => 's3',
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
    'bucket' => env('AWS_CDN_BUCKET'),
],
```

#### 2. Publish Config File

[](#2-publish-config-file)

```
$ php artisan vendor:publish --provider="Arubacao\AssetCdn\AssetCdnServiceProvider"
```

#### 3. Edit `cdn_url` and `filesystem.disk`

[](#3-edit-cdn_url-and-filesystemdisk)

```
// config/asset-cdn.php

[
    'cdn_url' => 'https://cdn.mysite.com',
    'filesystem' => [
        'disk' => 'asset-cdn',
    ],
]
```

#### 4. Edit `files` in `config/asset-cdn.php`

[](#4-edit-files-in-configasset-cdnphp)

*Only required if you plan to manage your assets via the provided commands: `asset-cdn:push`, `asset-cdn:sync`, `asset-cdn:empty`*

**`files` always assumes a relative path from the `public` directoy**

- `ignoreDotFiles`
    Excludes "hidden" directories and files (starting with a dot).
- `ignoreVCS`
    Ignore version control directories.
- `include`
    **Any** file that matches at least one `include` rule, will be included. **No** file is included by default.

    - `paths`
        Define **paths** that should be available on the CDN.
        The following example will match **any** file in **any** `js` or `css` path it can find in the `public` directory.

        ```
        'include' => [
            'paths' => [
                'js',
                'css'
            ],
        ]

        /*
         * This config would try to find:
         * '/var/www/html/public/js'
         * '/var/www/html/public/css'
         * but also any other 'js' or 'css' path e.g.
         * '/var/www/html/public/vendor/js'
         * '/var/www/html/public/vendor/css'
         * You could explicitly exclude paths later
         */
        ```
    - `files`
        Define **files** that should be available on the CDN.
        The following example will match **any** file that starts with `js/back.app.js` in the `public` directory.

        ```
        'include' => [
            'files' => [
                'js/app.js',
            ],
        ],

        /*
         * This config would try to find:
         * '/var/www/html/public/js/app.js'
         * but also any other file that matches the path + filename e.g.
         * '/var/www/html/public/vendor/js/app.js'
         * You could explicitly exclude these files later
         */
        ```
    - `extensions`
        Define **filetypes** that should be available on the CDN.
        The following example will match **any** file of type `*.css` or `*.js` in the `public` directory.

        ```
        'include' => [
            'extensions' => [
                '*.js',
                '*.css',
            ],
        ],
        ```
    - `patterns`
        Define **patterns** for files that should be available on the CDN.
        The following example will match **any** file that starts with letters `a` or `b` in the `public` directory.

        ```
        /*
         * Patterns can be globs, strings, or regexes
         */

        'include' => [
            'patterns' => [
                '/^[a-b]/i', //  starting with letters a-b
            ],
        ],
        ```
- `exclude`
    **Any** file that matches at least one `exclude` rule, will be excluded. Files that are excluded will **never** be included, even if they have been explicitly included. Rules are identical as described above.

#### 5. Set Additional Configurations for Uploaded Files

[](#5-set-additional-configurations-for-uploaded-files)

`filesystem.options` are passed directly to the [Filesystem](https://github.com/thephpleague/flysystem/blob/1.0.43/src/FilesystemInterface.php#L232)which eventually calls the underlying Storage driver e.g. S3.
Please refer to the corresponding storage driver documentation for available configuration options.
The following example is recommended for AWS S3.

```
// config/asset-cdn.php

[
    'filesystem' => [
        'disk' => 'asset-cdn',
        'options' => [
            'ACL' => 'public-read', // File is available to the public, independent of the S3 Bucket policy
            'CacheControl' => 'max-age=31536000, public', // Sets HTTP Header 'cache-control'. The client should cache the file for max 1 year
        ],
    ],
]
```

#### 6. Set Environment Variable `USE_CDN`

[](#6-set-environment-variable-use_cdn)

```
# .env

USE_CDN=true # Enables asset-cdn
USE_CDN=false # Disables asset-cdn (default)
```

Usage
-----

[](#usage)

#### Commands

[](#commands)

**Recommended**
Sync assets that have been defined in the config to the CDN. Only pushes changes/new assets. Deletes locally removed files on CDN.

```
$ php artisan asset-cdn:sync
```

Pushes assets that have been defined in the config to the CDN. Pushes all assets. Does not delete files on CDN.

```
$ php artisan asset-cdn:push
```

Deletes all assets from CDN, independent from config file.

```
$ php artisan asset-cdn:empty
```

#### Serving Assets

[](#serving-assets)

Replace `mix()` with `mix_cdn()`. Replace `asset()` with `asset_cdn()`.

Development
-----------

[](#development)

```
$ composer test
$ composer test:phpunit9
$ composer lint
$ composer analyse
```

Quality recommendations are tracked in [QUALITY.md](QUALITY.md).

Credits:
--------

[](#credits)

Icon from [www.flaticon.com](http://www.flaticon.com/)
Unmaintained git repo by [Vinelab](https://github.com/Vinelab/cdn) for inspiration only

Todo's:
-------

[](#todos)

- Video Tutorial: How to use S3/Cloudfront
- Write test for `ignoreVCS` finder config
- Write test for `ignoreDotFiles` finder config
- Extend `CombinedFinderTest`

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance95

Actively maintained with recent releases

Popularity48

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 98.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~429 days

Recently: every ~614 days

Total

8

Last Release

38d ago

PHP version history (3 changes)0.1.0PHP ^7.0

0.2.5PHP ^7.0|^8.0

0.3.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7462542?v=4)[Christopher Lass](/maintainers/arubacao)[@arubacao](https://github.com/arubacao)

---

Top Contributors

[![arubacao](https://avatars.githubusercontent.com/u/7462542?v=4)](https://github.com/arubacao "arubacao (71 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

---

Tags

cdncloudfrontcontent-delivery-networklaravellaravelcdncontent delivery networkAWS Cloudfront

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/arubacao-asset-cdn/health.svg)

```
[![Health](https://phpackages.com/badges/arubacao-asset-cdn/health.svg)](https://phpackages.com/packages/arubacao-asset-cdn)
```

###  Alternatives

[publiux/laravelcdn

Content Delivery Network (CDN) Package for Laravel

157234.9k](/packages/publiux-laravelcdn)[vinelab/cdn

Content Delivery Network (CDN) Package for Laravel

217244.0k1](/packages/vinelab-cdn)[juhasev/laravelcdn

Content Delivery Network (CDN) Package for Laravel

1921.1k](/packages/juhasev-laravelcdn)[slimani/filament-media-manager

A media manager plugin for Filament.

126.9k](/packages/slimani-filament-media-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
