nabu / yii2-compressr
v0.0.4
2020-11-03 05:03 UTC
Requires
- php: >=7.1.0
- mrclay/minify: ^3.0.3
- tedivm/jshrink: ^1.3.0
- yiisoft/yii2: ^2
This package is auto-updated.
Last update: 2024-09-29 05:42:57 UTC
README
本扩展提供了处理和合并本地资源的能力,从而减轻开发者在项目中对使用的资源和它们组织方式的严格控制。
这还可以通过减小页面大小和减少额外文件的加载来加快页面加载速度。
JavaScript
扩展将页面中包含的所有.js文件合并在一起,将其最小化,并将结果作为一个单独的.js文件包含在页面中。这个生成的文件将被缓存。
所有内联JavaScript都将被最小化,并保持在页面上的同一位置。您可以设置选项来缓存这些生成的部分,以防止相同代码部分的多次生成。
CSS
与JavaScript处理类似,所有.css文件都将被最小化,并作为一个单独的.css文件包含在页面中。这个生成的文件将被缓存。
所有内联CSS都将合并并最小化。与JavaScript处理类似,您可以设置选项来缓存这些生成的代码部分。
HTML
扩展还提供了对页面上的整个HTML进行最小化的能力。组件中使用了两种生成策略
安装
将 "nabu/yii2-compressr": ">=0.0.4" 添加到 composer.json 或运行
composer require --prefer-dist nabu/yii2-compressr ">=0.0.4"
使用方法
[
'bootstrap' => ['compressr'],
'components' => [
...
'compressr' =>
[
'class' => 'nabu\yii2\compressr\Compressr',
'enabled' => true, // enables component. possible use: 'enabled' => YII_ENV_PROD
'compressJs' => true, // compress and minify whole javascript on page
'jsCutComments' => true, // cut comments in javascript code
'jsCacheInlineParts' => true, // cache inline code parts. need the cache to be configured and enabled
'compressCss' => true, // compress and minify whole css on page
'cssCacheInlineParts' => true, // cache inline code parts. need the cache to be configured and enabled
'compressHtml' => true, // compress html
// possible options: HtmlCompressStrategy::MRCLAY or HtmlCompressStrategy::TYLER
'htmlCompressStrategy' => \nabu\yii2\compressr\html\HtmlCompressStrategy::MRCLAY,
],
]
]
配置文件
第一次调用重页面
后续时间使用缓存