iturgeon/qasset
Composer 安装命令:
composer require iturgeon/qasset
包简介
FuelPHP CSS and Javascript asset management
README 文档
README
This library lets you manage Javascript and CSS includes in FuelPHP using configuration files like Casset, minus all the the processing features. I switched to using pre-processors for all of this stuff, so I wanted a simpler library to manage assets.
Install
Install using Composer, if qAsset isn't uploaded to Packagist, add this repo using the repositories directive as shown below.
"repositories" : [ { "url":"https://github.com/iturgeon/qAsset.git", "type":"git" } ], "require": { "php": ">=5.4", "iturgeon/qasset": "1.0.0" },
Configuration
Groups, and default groups can be configured in config files. There is a config for js (fuel/app/config/js.php), and one for css (css.php).
Here is a sample css.php config
<?php return [ // Reduces groups with the same name down to one // 'remove_group_duplicates' => true, // default = true // define paths shortcuts like Casset does 'paths' => [ 'gfonts' => '//fonts.googleapis.com/', 'theme' => '/themes/'.Config::get('theme.active', 'default').'/assets/css/', 'assets' => '/assets/css' ], // groups to always load, and where to place them 'always_load_groups' => [ // default placement 'default' => [ 'main', // groups 'fonts', ], // custom footer placement (more useful for js then it would be css!) 'footer' => [ 'angular' // group ] ], 'groups' => [ // group is in the always_load_groups above, inserted into the default placement 'fonts' => [ // same as: '//fonts.googleapis.com/css?family=AWESOMEFONT:400,700,900' 'gfonts::css?family=AWESOMEFONT:400,700,900' ], // group is in the always_load_groups above, inserted into the default placement 'main' => [ 'theme::site.css', 'theme::normalize.min.css', ], 'homepage' => [ 'theme::homepage.css', ], ], // Change the precalulated hash config file name, defaults to 'asset_hash.json' // Supports any fuelphp config format 'hash_file' => 'asset_hash.json' ];
Cache Busting with precalculated Hashes
qAsset allows you to load pre-calculated file hashes to append to urls for the purpose of cache busting. Many pre-processors allow you pre-calculate file hashes like hash-assets-webpack-plugin or gulp-hashsum-json while building those files, this little feature will support those hashes.
By default css and js load from asset_hash.json, but they can be configured to load seperate files if that suits your needs better.
That config file needs to return an associative array where the key is the file reletive to the public directory, and the value is the hash
Ex:
{
"/assets/file.js": "hash_value",
"/assets/file2.js": "other_value"
}
When included in the page, these 2 files will have their hash appended for the purposes of cache busting.
<script src="/assets/file.js?hash_value"></script> <script src="/assets/file2.js?other_value"></script>
Usage
You can prepare CSS and JS inline in your controller methods, I find this easy for quick and dirty setup. Later I come back and move reusables to the config file.
Home Page Controler
public function action_index() { // insert the javascript group 'homepage' (defined in js.php config) into the footer placement Js::push_group('homepage', 'footer'); // adds a script directly w/o using groups, send an array of scripts if you want Js::push('theme::homepage.min.js'); // adds inline javascript to the footer Js::push_inline('var CONST = true;', 'footer'); // Css works the same way as Js Css::push_group(['homepage', 'holiday']); // you can send arrays! Css::push(['theme::one.css', 'theme::two.css']); // more arrays here Css::push_inline('div.total-mistake{ display:none; }'); // for those last minute monkey patches $theme = Theme::instance(); $theme->set_template('layouts/homepage') ->set('title', 'Welcome to the Magic Show'); return Response::forge($theme); }
Home Page Layout
<!DOCTYPE html> <html> <head> <title><?= $title ?> | Mystical Website</title> <!-- Renders the 'default' placement for Css and Js with no arguments --> <?= Css::render() ?> <?= Js::render() ?> </head> <body> <!-- YOUR PAGE HERE --> <!-- Render the Javascript 'footer' placement --> <?= Js::render('footer') ?> </body> </html>
iturgeon/qasset 适用场景与选型建议
iturgeon/qasset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.05k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「javascript」 「css」 「JS」 「fuelphp」 「casset」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iturgeon/qasset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iturgeon/qasset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iturgeon/qasset 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Asset Management for PHP
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
统计信息
- 总下载量: 6.05k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-30