PHPackages                             juhasev/laravelcdn - 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. juhasev/laravelcdn

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

juhasev/laravelcdn
==================

Content Delivery Network (CDN) Package for Laravel

v4.1.0(1y ago)1820.4k↓50%6MITPHPPHP ^8.1

Since Jan 17Pushed 1y ago2 watchersCompare

[ Source](https://github.com/juhasev/LaravelCdn)[ Packagist](https://packagist.org/packages/juhasev/laravelcdn)[ RSS](/packages/juhasev-laravelcdn/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (30)Used By (0)

[![alt text](./laravel-cdn.svg "Laravel CDN")](./laravel-cdn.svg)

Laravel CDN Assets Manager
==========================

[](#laravel-cdn-assets-manager)

##### Content Delivery Network Package for Laravel

[](#content-delivery-network-package-for-laravel)

The package provides the developer the ability to upload their assets (or any public file) to a CDN with a single artisan command. And then it allows them to switch between the local and the online version of the files.

##### History

[](#history)

This project has had multiple homes and unfortunately the previous maintainers have lost interest into this project. I am planning on maintaining this package as we have several projects that make use of it. This is the latest version of Laravel CDN.

###### Fork from [Publiux/laravelcdn](https://github.com/publiux/laravelcdn)

[](#fork-from-publiuxlaravelcdn)

###### Fork From [Vinelab/cdn](https://github.com/Vinelab/cdn)

[](#fork-from-vinelabcdn)

This project has been forked originally from . All credit for the original work goes there.

#### Laravel Support

[](#laravel-support)

- If you are using Laravel 10 use `v4.*`
- If you are using Laravel 9 use `v3.*`
- If you are using Laravel 8 use `v2.2.0`
- If you are using Laravel 7 use `v2.1.0`

Highlights
----------

[](#highlights)

- Amazon Web Services (AWS) - S3
- DigitalOcean (DO) - Spaces
- Artisan command to upload content to CDN
- Simple Facade to access CDN assets

### Questions

[](#questions)

1. Is this package an alternative to Laravel FileSystem and do they work together?

- No, the package was introduced in Laravel 4 and it's main purpose is to manage your CDN assets by loading them from the CDN into your Views pages, and easily switch between your Local and CDN version of the files. As well it allows you to upload all your assets with single command after specifying the assets directory and rules. The FileSystem was introduced in Laravel 5 and it's designed to facilitate the loading/uploading of files form/to a CDN. It can be used the same way as this Package for loading assets from the CDN, but it's harder to upload your assets to the CDN since it expect you to upload your files one by one. As a result this package still not a replacement of the Laravel FileSystem and they can be used together.

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

[](#installation)

#### Via Composer

[](#via-composer)

Require `juhasev/laravelcdn` in your project:

```
composer require juhasev/laravelcdn
```

*If you are using Laravel 5.4 or below, you need to register the service provider:*

Laravel 5.4 and below: Add the service provider and facade to `config/app.php`:

```
'providers' => array(
     //...
     SampleNinja\LaravelCdn\CdnServiceProvider::class,
)

```

```
'aliases' => array(
     //...
     'CDN' => SampleNinja\LaravelCdn\Facades\CdnFacadeAccessor::class
)

```

*If you are using Laravel 5.5, there is no need to register the service provider as this package is automatically discovered.*

Publish the package config file:

```
php artisan vendor:publish --provider 'SampleNinja\LaravelCdn\CdnServiceProvider'
```

Environment Configuration
-------------------------

[](#environment-configuration)

This package can be configured by editing the config/app.php file. Alternatively, you can set many of these options in as environment variables in your '.env' file.

##### AWS Credentials

[](#aws-credentials)

Set your AWS Credentials and other settings in the `.env` file.

*Note: you should always have an `.env` file at the project root, to hold your sensitive information. This file should usually not be committed to your VCS.*

```
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

```

##### CDN URL

[](#cdn-url)

Set the CDN URL:

```
'url' => env('CDN_Url', 'https://s3.amazonaws.com'),

```

This can altered in your '.env' file as follows:

```
CDN_Url=
```

##### Bypass

[](#bypass)

To load your LOCAL assets for testing or during development, set the `bypass` option to `true`:

```
'bypass' => env('CDN_Bypass', false),

```

This can be altered in your '.env' file as follows:

```
CDN_Bypass=

```

##### Cloudfront Support

[](#cloudfront-support)

```
'cloudfront'    => [
    'use' => env('CDN_UseCloudFront', false),
    'cdn_url' => env('CDN_CloudFrontUrl', false)
],

```

This can be altered in your '.env' file as follows:

```
CDN_UseCloudFront=
CDN_CloudFrontUrl=

```

##### Default CDN Provider

[](#default-cdn-provider)

For now, the only CDN provider available is AwsS3. Although, as DO natively support the AWS API, you can utilise it by also providing the endpoint, please see the cdn.php config for more info. This option cannot be set in '.env'.

```
'default' => 'AwsS3',

```

##### CDN Provider Configuration

[](#cdn-provider-configuration)

```
'aws' => [

    's3' => [

        'version'   => 'latest',
        'region'    => '',
        'endpoint'  => '', // For DO Spaces

        'buckets' => [
            'my-backup-bucket' => '*',
        ]
    ]
],

```

###### Multiple Buckets

[](#multiple-buckets)

```
'buckets' => [

    'my-default-bucket' => '*',

    // 'js-bucket' => ['public/js'],
    // 'css-bucket' => ['public/css'],
    // ...
]

```

#### Files &amp; Directories

[](#files--directories)

###### Include:

[](#include)

Specify directories, extensions, files and patterns to be uploaded.

```
'include'    => [
    'directories'   => ['public/dist'],
    'extensions'    => ['.js', '.css', '.yxz'],
    'patterns'      => ['**/*.coffee'],
],

```

###### Exclude:

[](#exclude)

Specify what to be ignored.

```
'exclude'    => [
    'directories'   => ['public/uploads'],
    'files'         => [''],
    'extensions'    => ['.TODO', '.txt'],
    'patterns'      => ['src/*', '.idea/*'],
    'hidden'        => true, // ignore hidden files
],

```

##### Other Configurations

[](#other-configurations)

```
'acl'           => 'public-read',
'metadata'      => [ ],
'expires'       => gmdate("D, d M Y H:i:s T", strtotime("+5 years")),
'cache-control' => 'max-age=2628000',

```

You can always refer to the AWS S3 Documentation for more details: [aws-sdk-php](http://docs.aws.amazon.com/aws-sdk-php/v3/guide/)

Usage
-----

[](#usage)

You can 'push' your assets to your CDN and you can 'empty' your assets as well using the commands below.

#### Push

[](#push)

Only changed assets are pushed to the CDN. (THanks, )

Upload assets to CDN

```
php artisan cdn:push
```

You can specify a folder upload prefix in the cdn.php config file. Your assets will be uploaded into that folder on S3.

#### Empty

[](#empty)

Delete assets from CDN

```
php artisan cdn:empty
```

CAUTION: This will erase your entire bucket. This may not be what you want if you are specifying an upload folder when you push your assets.

#### Load Assets

[](#load-assets)

Use the facade `CDN` to call the `CDN::asset()` function.

*Note: the `asset` works the same as the Laravel `asset` it start looking for assets in the `public/` directory:*

```
{{CDN::asset('assets/js/main.js')}}        // example result: https://js-bucket.s3.amazonaws.com/public/assets/js/main.js

{{CDN::asset('assets/css/style.css')}}        // example result: https://css-bucket.s3.amazonaws.com/public/assets/css/style.css
```

*Note: the `elixir` works the same as the Laravel `elixir` it loads the manifest.json file from build folder and choose the correct file revision generated by gulp:*

```
{{CDN::elixir('assets/js/main.js')}}        // example result: https://js-bucket.s3.amazonaws.com/public/build/assets/js/main-85cafe36ff.js

{{CDN::elixir('assets/css/style.css')}}        // example result: https://css-bucket.s3.amazonaws.com/public/build/assets/css/style-2d558139f2.css
```

*Note: the `mix` works the same as the Laravel 5.4 `mix` it loads the mix-manifest.json file from public folder and choose the correct file revision generated by webpack:*

```
{{CDN::mix('/js/main.js')}}        // example result: https://js-bucket.s3.amazonaws.com/public/js/main-85cafe36ff.js

{{CDN::mix('/css/style.css')}}        // example result: https://css-bucket.s3.amazonaws.com/public/css/style-2d558139f2.css
```

To use a file from outside the `public/` directory, anywhere in `app/` use the `CDN::path()` function:

```
{{CDN::path('private/something/file.txt')}}        // example result: https://css-bucket.s3.amazonaws.com/private/something/file.txt
```

Test
----

[](#test)

To run the tests, run the following command from the project folder.

```
$ ./vendor/bin/phpunit
```

Support
-------

[](#support)

Please request support or submit issues [via Github](https://github.com/juhasev/laravelcdn/issues)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/juhasev/LaravelCdn/blob/master/CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Juha Vehnia](https://github.com/juhasev) (forker)
- [Raul Ruiz](https://github.com/publiux) (original forker)
- [Mahmoud Zalt](https://github.com/Mahmoudz) (original developer)
- [Filipe Garcia](https://github.com/filipegar) (contributred pre-fork, uncredited pull request for duplicate uploading verification)
- [Contributors from original project](https://github.com/Vinelab/cdn/graphs/contributors)
- [All Contributors for this Fork](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/juhasev/LaravelCdn/blob/master/LICENSE) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 52.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 ~134 days

Recently: every ~340 days

Total

24

Last Release

669d ago

Major Versions

v1.0.3 → 2.0.02017-09-05

v2.2.0 → v3.0.02022-04-29

v3.0.0 → v4.0.02023-09-05

PHP version history (5 changes)v1.0.0PHP &gt;=5.5.9

v2.1.0PHP &gt;=7.1

v2.2.0PHP ^7.3

v3.0.0PHP ^7.3|^8.0

v4.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10157670?v=4)[Juha Vehnia](/maintainers/juhasev)[@juhasev](https://github.com/juhasev)

---

Top Contributors

[![publiux](https://avatars.githubusercontent.com/u/2847188?v=4)](https://github.com/publiux "publiux (80 commits)")[![juhasev](https://avatars.githubusercontent.com/u/10157670?v=4)](https://github.com/juhasev "juhasev (34 commits)")[![leMaur](https://avatars.githubusercontent.com/u/2118799?v=4)](https://github.com/leMaur "leMaur (20 commits)")[![nyxsoftwaresystems](https://avatars.githubusercontent.com/u/71080572?v=4)](https://github.com/nyxsoftwaresystems "nyxsoftwaresystems (11 commits)")[![ngrampsas](https://avatars.githubusercontent.com/u/9724046?v=4)](https://github.com/ngrampsas "ngrampsas (3 commits)")[![samdoidge](https://avatars.githubusercontent.com/u/845238?v=4)](https://github.com/samdoidge "samdoidge (1 commits)")[![markokeeffe](https://avatars.githubusercontent.com/u/1211393?v=4)](https://github.com/markokeeffe "markokeeffe (1 commits)")[![mul14](https://avatars.githubusercontent.com/u/113989?v=4)](https://github.com/mul14 "mul14 (1 commits)")[![Arslanharoon](https://avatars.githubusercontent.com/u/8645484?v=4)](https://github.com/Arslanharoon "Arslanharoon (1 commits)")

---

Tags

laravelamazons3awsuploadcdnaws-s3content delivery networkAssets Upload

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/juhasev-laravelcdn/health.svg)

```
[![Health](https://phpackages.com/badges/juhasev-laravelcdn/health.svg)](https://phpackages.com/packages/juhasev-laravelcdn)
```

###  Alternatives

[publiux/laravelcdn

Content Delivery Network (CDN) Package for Laravel

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

Content Delivery Network (CDN) Package for Laravel

217240.8k1](/packages/vinelab-cdn)[aws/aws-sdk-php-laravel

A simple Laravel 9/10/11/12/13 service provider for including the AWS SDK for PHP.

1.7k35.6M75](/packages/aws-aws-sdk-php-laravel)

PHPackages © 2026

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