师阳 2016-11-16 22:47:30 6119次浏览 2条评论 13 2 0

通过合并CSS,JS文件,以减少请求,提高加载速度。这个插件可以通过 AssetBundle 来自动压缩页面出现的CSS,JS文件,比官方手册介绍合并方法省事多了。

安装:

composer require "rmrevin/yii2-minify-view"

配置:

<?php

return [
    // ...
    'components' => [
        // ...
        'view' => [
            'class' => '\rmrevin\yii\minify\View',
            'enableMinify' => !YII_DEBUG,
            'concatCss' => true, // concatenate css
            'minifyCss' => true, // minificate css
            'concatJs' => true, // concatenate js
            'minifyJs' => true, // minificate js
            'minifyOutput' => true, // minificate result html page
            'web_path' => '@web', // path alias to web base
            'base_path' => '@webroot', // path alias to web base
            'minify_path' => '@webroot/minify', // path alias to save minify result
            'js_position' => [ \yii\web\View::POS_END ], // positions of js files to be minified
            'force_charset' => 'UTF-8', // charset forcibly assign, otherwise will use all of the files found charset
            'expand_imports' => true, // whether to change @import on content
            'compress_options' => ['extra' => true], // options for compress
            'excludeBundles' => [
                \dev\hellowrld\AssetBundle::class, // exclude this bundle from minification
            ],
        ]
    ]
];

原链接:https://github.com/rmrevin/yii2-minify-view

转载署名本文作者且注明文章出处^_^

觉得很赞
您需要登录后才可以评论。登录 | 立即注册