Giter Club home page Giter Club logo

cdn's Introduction

CDN Assets Manager

Latest Stable Version Latest Unstable Version Total Downloads License Build Status

Content Delivery Network Package for Laravel 4

Upload static assets of your choice to a CDN and have the file paths replaced with full URLs.

Install

Via Composer

  • Add the package to your composer.json and run composer update

    {
        "require": {
            "vinelab/cdn": "*"
        }
    }
  • Add the service provider to app/config/app.php:

    'providers' => array(
        '...',
        'Vinelab\Cdn\CdnServiceProvider',
        '...'
    ),

The service provider will register all the required classes for this package and will also alias the Cdn class to CdnFacadeProvider so you can simply use the Cdn facade anywhere in your app.

Configuration

Publish the package config file:

php artisan config:publish vinelab/cdn

and check it out at app/config/packages/vinelab/cdn/cdn.php

In case you would like to have environment-based configuration app/config/packages/vinelab/cdn/[ENV]/cdn.php

Providers

Supported Providers:

  • Amazon Web Services - S3 (Default)

Default Provider

'default' => 'aws-s3',

CDN Provider Setup

    'aws' => [

        's3' => [

            'credentials' => [
                'key'    => '',
                'secret'    => '',
            ],

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

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

Files & Directories

Include

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

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

Exclude

Specify what to be ignored.

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

URL

Set the CDN URL:

    'url' => 'https://s3.amazonaws.com',

Threshold

Determines how many files to be uploaded concurrently.

Will clear the buffer when the threshold has been reached, be careful when setting this to a high value not to exceed what you have allowed in your PHP configuration.

    'threshold' => 10,

Bypass

To load your local assets (not the CDN assets) for testing or during development, set the bypass option to true:

    'bypass' => true,

Usage

Push

Upload your assets with

php artisan cdn:push

Load Assets

Now you can 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')}}
    // https://js-bucket.s3.amazonaws.com/public/assets/js/main.js

    {{Cdn::asset('assets/css/main.css')}}
    // https://css-bucket.s3.amazonaws.com/public/assets/css/main.css

If you want to use a file from outside the public/ directory anywhere in app/ you can use the Cdn::path() function to do that:

    {{Cdn::path('public/assets/js/main.js')}}
    // https://js-bucket.s3.amazonaws.com/public/assets/js/main.js

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

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

cdn's People

Contributors

martyphee avatar mulkave avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.