orchestra/asset
Composer 安装命令:
composer require orchestra/asset
包简介
Asset Component for Orchestra Platform
README 文档
README
Asset Component is a port of Laravel 3 Asset for Orchestra Platform. The component main functionality is to allow asset declaration to be handle dynamically and asset dependencies can be resolve directly from the container. It however is not intended to becoma an asset pipeline package for Laravel, for such purpose we would recommend to use Grunt or Gulp.
Table of Content
Version Compatibility
| Laravel | Asset |
|---|---|
| 5.5.x | 3.5.x |
| 5.6.x | 3.6.x |
| 5.7.x | 3.7.x |
| 5.8.x | 3.8.x |
| 6.x | 4.x |
| 7.x | 5.x |
| 8.x | 6.x |
Installation
To install through composer, run the following command from terminal:
composer require "orchestra/asset"
Configuration
Add following service providers in config/app.php.
'providers' => [ // ... Orchestra\Asset\AssetServiceProvider::class, Collective\Html\HtmlServiceProvider::class, ],
Aliases
You might want to add Orchestra\Support\Facades\Asset to class aliases in config/app.php:
'aliases' => [ // ... 'Asset' => Orchestra\Support\Facades\Asset::class, ],
Usage
Registering Assets
The Asset class provides a simple way to manage the CSS and JavaScript used by your application. To register an asset just call the add method on the Asset class:
Registering an asset:
Asset::add('jquery', 'js/jquery.js');
The add method accepts three parameters. The first is the name of the asset, the second is the path to the asset relative to the public directory, and the third is a list of asset dependencies (more on that later). Notice that we did not tell the method if we were registering JavaScript or CSS. The add method will use the file extension to determine the type of file we are registering.
Dumping Assets
When you are ready to place the links to the registered assets on your view, you may use the styles or scripts methods:
Dumping assets into a view:
<head> {!! Asset::styles() !!} {!! Asset::scripts() !!} </head>
Above code can also be simplified as:
<head> {!! Asset::show() !!} </head>
Asset Dependencies
Sometimes you may need to specify that an asset has dependencies. This means that the asset requires other assets to be declared in your view before it can be declared. Managing asset dependencies couldn't be easier in Laravel. Remember the "names" you gave to your assets? You can pass them as the third parameter to the add method to declare dependencies:
Registering a bundle that has dependencies:
Asset::add('jquery-ui', 'js/jquery-ui.js', 'jquery');
In this example, we are registering the jquery-ui asset, as well as specifying that it is dependent on the jquery asset. Now, when you place the asset links on your views, the jQuery asset will always be declared before the jQuery UI asset. Need to declare more than one dependency? No problem:
Registering an asset that has multiple dependencies:
Asset::add('jquery-ui', 'js/jquery-ui.js', ['first', 'second']);
Asset Containers
To increase response time, it is common to place JavaScript at the bottom of HTML documents. But, what if you also need to place some assets in the head of your document? No problem. The asset class provides a simple way to manage asset containers. Simply call the container method on the Asset class and mention the container name. Once you have a container instance, you are free to add any assets you wish to the container using the same syntax you are used to:
Retrieving an instance of an asset container:
Asset::container('footer')->add('example', 'js/example.js');
Dumping that assets from a given container:
{!! Asset::container('footer')->scripts() !!}
Asset Versioning
Another option to increase response time is by utilizing browser caching, while there few ways to do this we pick last modified time as our way to version the Asset.
Asset::container()->addVersioning(); // or alternatively Asset::addVersioning();
Note: this would only work with local asset.
You can remove adding versioning number by using:
Asset::container()->removeVersioning(); // or alternatively Asset::removeVersioning();
orchestra/asset 适用场景与选型建议
orchestra/asset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 177.96k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2013 年 05 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「asset」 「laravel」 「orchestra-platform」 「orchestral」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 orchestra/asset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 orchestra/asset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 orchestra/asset 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Orchestra Platform Foundation
Orchestra Platform
CMS Extension for Orchestra Platform
Contracts for Orchestra Platform
Tenant based Database Schema Manager for Laravel
Model Component for Orchestra Platform
统计信息
- 总下载量: 177.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 55
- 点击次数: 18
- 依赖项目数: 5
- 推荐数: 15
其他信息
- 授权协议: MIT
- 更新时间: 2013-05-14