PHP code example of mehedi / asset-cdn

1. Go to this page and download the library: Download mehedi/asset-cdn library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mehedi / asset-cdn example snippets


// head.blade.php
<link rel="stylesheet" href="{{ mix_cdn('/css/app.css') }}">

// config/app.php

'providers' => [
    // Other Service Providers
    \Arubacao\AssetCdn\AssetCdnServiceProvider::class,
],

// config/filesystem.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'),
],

// config/asset-cdn.php

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

        '    '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' => [
                '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' => [
                '*.js',
                '*.css',
            ],
        ],
        

        /*
         * Patterns can be globs, strings, or regexes
         */
         
        '    ],
        ],
        

// 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 
        ],
    ],
]
bash
$ php artisan asset-cdn:sync
bash
$ php artisan vendor:publish --provider="Arubacao\AssetCdn\AssetCdnServiceProvider"
bash
$ php artisan asset-cdn:sync
bash
$ php artisan asset-cdn:empty