Table of Contents
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.
https://github.com/Vinelab/cdn
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 ],
USAGE:
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: https://www.keycdn.com/support/laravel-cdn-integration
This approach is fairly easy and you don’t need to upload anything if you’re using a pull zone.
Digital Transformation begins here!
Let us write your business’s growth story by offering innovative, scalable and result-driven IT solutions. Do you have an idea that has the potential to bring a change in the world? Don’t hesitate. Share with our experts and we will help you to achieve it.