Protection Status

Search Results for:

Our Blog

How to Implement CDN in Laravel?

July 11, 2017 | 2 Minutes Read
Tarun Bansal
July 11, 2017

Implementing CDN into Laravel is no more easier for a nontechnical person. It needs a lot of efforts to implement a Content Delivery Network into Laravel! We would let you understand the entire process of implementing CDN into Laravel with the help of CDN Assets Manager Package. Have a look into this and move on reading to find various ways for the same.

Install it Via Composer:

{ “require”: { “vinelab/cdn”: “*” }

Add your CDN Credentials:

‘credentials’ => [ ‘key’ => ”, ‘secret’ => ”, ], ‘buckets’ => [ ‘bucket-name-here’ => ‘*’, ]

Specify directories, extensions, files and patterns to be uploaded

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

Also specify what to be ignored

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

Run this artisan command to push your assets to the CDN.

  • Run this artisan command to push your assets to the CDN.
  • php artisan cdn:push
  • Use it as follow in your Views or anywhere else in your code:
  • {{ Cdn::asset(‘public/assets/js/script.js’) }}
  • {{ Cdn::asset(‘public/assets/css/main.css’) }}

You can create a helper as described here:

This approach is fairly easy and you don’t need to upload anything if you’re using a pull zone.

Our Acknowledgements

We take pride in receiving recognition and accolades by offering unmatched IT and digital marketing solutions

Get a Free Quote