{"id":17855362,"url":"https://github.com/arubacao/asset-cdn","last_synced_at":"2025-04-06T07:15:07.339Z","repository":{"id":30028845,"uuid":"123728821","full_name":"arubacao/asset-cdn","owner":"arubacao","description":"Serve Laravel Assets from a Content Delivery Network (CDN)","archived":false,"fork":false,"pushed_at":"2023-02-20T19:40:52.000Z","size":2016,"stargazers_count":112,"open_issues_count":7,"forks_count":26,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-09-19T14:13:34.781Z","etag":null,"topics":["cdn","cloudfront","content-delivery-network","laravel"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arubacao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-03T20:30:31.000Z","updated_at":"2024-06-24T00:44:39.000Z","dependencies_parsed_at":"2024-06-19T01:52:36.998Z","dependency_job_id":null,"html_url":"https://github.com/arubacao/asset-cdn","commit_stats":{"total_commits":67,"total_committers":1,"mean_commits":67.0,"dds":0.0,"last_synced_commit":"25718d59e6edf37c1975e68413851e7310ea0964"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arubacao%2Fasset-cdn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arubacao%2Fasset-cdn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arubacao%2Fasset-cdn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arubacao%2Fasset-cdn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arubacao","download_url":"https://codeload.github.com/arubacao/asset-cdn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445682,"owners_count":20939961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cdn","cloudfront","content-delivery-network","laravel"],"created_at":"2024-10-28T02:04:04.917Z","updated_at":"2025-04-06T07:15:07.309Z","avatar_url":"https://github.com/arubacao.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/arubacao/asset-cdn/master/asset-cdn.png\"\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://packagist.org/packages/arubacao/asset-cdn\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/arubacao/asset-cdn.svg?style=flat-square\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/arubacao/asset-cdn/actions?query=workflow%3A%22Run+Tests%22\"\u003e\u003cimg alt=\"GitHub Workflow Status\" src=\"https://img.shields.io/github/workflow/status/arubacao/asset-cdn/Run%20Tests?style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://codecov.io/gh/arubacao/asset-cdn\"\u003e\u003cimg src=\"https://img.shields.io/codecov/c/github/arubacao/asset-cdn.svg?style=flat-square\" alt=\"Codecov\"\u003e\u003c/a\u003e\n\u003ca href=\"https://scrutinizer-ci.com/g/arubacao/asset-cdn\"\u003e\u003cimg src=\"https://img.shields.io/scrutinizer/g/arubacao/asset-cdn.svg?style=flat-square\" alt=\"Quality Score\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/arubacao/asset-cdn\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/arubacao/asset-cdn.svg?style=flat-square\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cstrong\u003e\nServe Laravel Assets from a Content Delivery Network (CDN)\n\u003c/strong\u003e\u003c/p\u003e\n\n## Introduction\n\nThis package lets you **push**, **sync**, **delete** and **serve** assets to/from a CDN of your choice e.g. AWS Cloudfront.  \nIt adds helper methods **`mix_cdn()`** and **`asset_cdn()`**.\n\n#### Simple Illustration\n```bash\n\u003e\u003e\u003e env('USE_CDN')\n=\u003e true\n```\n```bash\n$ php artisan asset-cdn:sync\n```\n```php\n// head.blade.php\n\u003clink rel=\"stylesheet\" href=\"{{ mix_cdn('/css/app.css') }}\"\u003e\n```\n```html\n\u003c!-- Result --\u003e\n\u003clink rel=\"stylesheet\" href=\"https://cdn.mysite.com/css/app.css?id=081861342e950012abe3\"\u003e\n```\n\n## Installation\nInstall this package via composer:\n\n```bash\n$ composer require arubacao/asset-cdn\n```\n\nAlso register the service provider:  \n_Only required for Laravel `\u003c=5.4`, for Laravel `\u003e=5.5` [auto-discovery](composer.json#L45) is enabled._\n```PHP\n// config/app.php\n\n'providers' =\u003e [\n    // Other Service Providers\n    \\Arubacao\\AssetCdn\\AssetCdnServiceProvider::class,\n],\n```\nNotes:  \n\n - `arubacao/asset-cdn` is functional and fully tested for Laravel `5.4` - `8.*` on PHP `7.0`, `7.1`, `7.2`, `7.3, 7.4`\n\n## Configuration\n\n#### 1. Configure Filesystem \n\n_Only required if you plan to manage your assets via the provided commands: `asset-cdn:push`, `asset-cdn:sync`, `asset-cdn:empty`_\n\n\n`arubacao/asset-cdn` utilizes [Laravel's Filesystem](https://laravel.com/docs/5.6/filesystem) to **push**, **sync**, **delete** assets to/from the CDN of your choice.\nTherefore, you have to configure and define a filesystem specific for CDN purposes. \nPlease follow the [official documentation]((https://laravel.com/docs/5.6/filesystem)).\n\nIf you plan to use AWS S3/Cloudfront you can use this configuration:\n```php\n// config/filesystem.php\n\n'asset-cdn' =\u003e [\n    'driver' =\u003e 's3',\n    'key' =\u003e env('AWS_ACCESS_KEY_ID'),\n    'secret' =\u003e env('AWS_SECRET_ACCESS_KEY'),\n    'region' =\u003e env('AWS_DEFAULT_REGION', 'us-east-1'),\n    'bucket' =\u003e env('AWS_CDN_BUCKET'),\n],\n```\n\n#### 2. Publish Config File\n```bash\n$ php artisan vendor:publish --provider=\"Arubacao\\AssetCdn\\AssetCdnServiceProvider\"\n```\n\n#### 3. Edit `cdn_url` and `filesystem.disk`\n```php\n// config/asset-cdn.php\n\n[\n    'cdn_url' =\u003e 'https://cdn.mysite.com',\n    'filesystem' =\u003e [\n        'disk' =\u003e 'asset-cdn',\n    ],\n]\n```\n\n#### 4. Edit `files` in `config/asset-cdn.php`\n_Only required if you plan to manage your assets via the provided commands: `asset-cdn:push`, `asset-cdn:sync`, `asset-cdn:empty`_\n\n**`files` always assumes a relative path from the `public` directoy**\n\n- `ignoreDotFiles`  \nExcludes \"hidden\" directories and files (starting with a dot).\n\n- `ignoreVCS`  \nIgnore version control directories.\n\n- `include`  \n**Any** file that matches at least one `include` rule, will be included. **No** file is included by default.\n\n    * `paths`  \nDefine **paths** that should be available on the CDN.  \nThe following example will match **any** file in **any** `js` or `css` path it can find in the `public` directory.\n\n        ```php\n        'include' =\u003e [\n            'paths' =\u003e [\n                'js', \n                'css'\n            ],\n        ]\n        \n        /*\n         * This config would try to find:\n         * '/var/www/html/public/js'\n         * '/var/www/html/public/css'\n         * but also any other 'js' or 'css' path e.g.\n         * '/var/www/html/public/vendor/js'\n         * '/var/www/html/public/vendor/css'\n         * You could explicitly exclude paths later\n         */\n        ```\n\n    * `files`  \nDefine **files** that should be available on the CDN.  \nThe following example will match **any** file that starts with `js/back.app.js` in the `public` directory.\n\n        ```php\n        'include' =\u003e [\n            'files' =\u003e [\n                'js/app.js',\n            ],\n        ],\n        \n        /*\n         * This config would try to find:\n         * '/var/www/html/public/js/app.js'\n         * but also any other file that matches the path + filename e.g.\n         * '/var/www/html/public/vendor/js/app.js'\n         * You could explicitly exclude these files later\n         */\n        ```\n\n     * `extensions`  \nDefine **filetypes** that should be available on the CDN.  \nThe following example will match **any** file of type `*.css` or `*.js` in the `public` directory.\n    \n        ```php\n        'include' =\u003e [\n            'extensions' =\u003e [\n                '*.js',\n                '*.css',\n            ],\n        ],\n        ```\n\n     * `patterns`  \nDefine **patterns** for files that should be available on the CDN.  \nThe following example will match **any** file that starts with letters `a` or `b` in the `public` directory.\n\n        ```php\n        /*\n         * Patterns can be globs, strings, or regexes\n         */\n         \n        'include' =\u003e [\n            'patterns' =\u003e [\n                '/^[a-b]/i', //  starting with letters a-b\n            ],\n        ],\n        ```\n\n- `exclude`  \n**Any** file that matches at least one `exclude` rule, will be excluded. Files that are excluded will **never** be included, even if they have been explicitly included.\nRules are identical as described above.\n\n\n#### 5. Set Additional Configurations for Uploaded Files\n\n`filesystem.options` are passed directly to the [Filesystem](https://github.com/thephpleague/flysystem/blob/1.0.43/src/FilesystemInterface.php#L232) \nwhich eventually calls the underlying Storage driver e.g. S3.  \nPlease refer to the corresponding storage driver documentation for available configuration options.  \nThe following example is recommended for AWS S3.  \n\n```php\n// config/asset-cdn.php\n\n[\n    'filesystem' =\u003e [\n        'disk' =\u003e 'asset-cdn',\n        'options' =\u003e [\n            'ACL' =\u003e 'public-read', // File is available to the public, independent of the S3 Bucket policy \n            'CacheControl' =\u003e 'max-age=31536000, public', // Sets HTTP Header 'cache-control'. The client should cache the file for max 1 year \n        ],\n    ],\n]\n```\n\n#### 6. Set Environment Variable `USE_CDN`\n```dotenv\n# .env\n\nUSE_CDN=true # Enables asset-cdn\nUSE_CDN=false # Disables asset-cdn (default)\n```\n\n## Usage\n\n#### Commands\n\n**Recommended**  \nSync assets that have been defined in the config to the CDN. Only pushes changes/new assets. Deletes locally removed files on CDN.\n```bash\n$ php artisan asset-cdn:sync\n```\n\nPushes assets that have been defined in the config to the CDN. Pushes all assets. Does not delete files on CDN.\n```bash\n$ php artisan asset-cdn:push\n```\n\nDeletes all assets from CDN, independent from config file.\n```bash\n$ php artisan asset-cdn:empty\n```\n\n#### Serving Assets\nReplace [`mix()`](https://laravel.com/docs/5.6/helpers#method-mix) with `mix_cdn()`.   \nReplace [`asset()`](https://laravel.com/docs/5.6/helpers#method-asset) with `asset_cdn()`.   \n\n\n## Credits:\nIcon from [www.flaticon.com](http://www.flaticon.com/)  \nUnmaintained git repo by [Vinelab](https://github.com/Vinelab/cdn) for inspiration only\n\n## Todo's:\n\n - Video Tutorial: How to use S3/Cloudfront \n - Write test for `ignoreVCS` finder config\n - Write test for `ignoreDotFiles` finder config\n - Extend `CombinedFinderTest`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farubacao%2Fasset-cdn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farubacao%2Fasset-cdn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farubacao%2Fasset-cdn/lists"}