Home php教程 PHP开发 Yii installs the EClientScript plug-in extension to implement css and js file code compression and merge loading functions

Yii installs the EClientScript plug-in extension to implement css and js file code compression and merge loading functions

Dec 30, 2016 pm 04:24 PM

The example of this article describes how Yii installs the EClientScript plug-in extension to implement css and js file code compression and merge loading functions. Share it with everyone for your reference, the details are as follows:

Extension plug-in download address, unzip and copy to /protected/vendor/

https://github.com/muayyad-alsadi/yii- EClientScript

main configuration file configures the plug-in, adds

//js,css代码压缩,合并
'clientScript' => array(
 'class' => 'application.vendor.yii-EClientScript.EClientScript',
 'combineScriptFiles' => TRUE, // By default this is set to true, set this to true if you'd like to combine the script files
 'combineCssFiles' => TRUE, // By default this is set to true, set this to true if you'd like to combine the css files
 'optimizeScriptFiles' => !YII_DEBUG, // @since: 1.1
 'optimizeCssFiles' => !YII_DEBUG, // @since: 1.1
 'optimizeInlineScript' => false, // @since: 1.6, This may case response slower
 'optimizeInlineCss' => false, // @since: 1.6, This may case response slower
),
Copy after login

tool class Unit.php in components, and places it in /protected/vendor/components, and defines the loading method in the class

/**
 * 注册JS 文件
 */
public function jsFile($file,$position=CClientScript::POS_HEAD,$media=array()){
 $cs=Yii::app()->getClientScript();
 $cs->registerScriptFile($file,$position,$media);
}
/**
 *注册CSS文件
 */
public function cssFile($file,$media=''){
 Yii::app()->getClientScript()->registerCssFile($file,$media);
}
Copy after login

template Calling css files and js files

<?php
//注册CSS文件,
Unit::cssFile(&#39;/css/home/base.css&#39;);
//result to:<link rel="stylesheet" type="text/css" href="/css/home/base.css" />
//IE6下加载CSS文件
Unit::cssFile(&#39;/css/form.css&#39;,&#39;lte IE 6&#39;);
//result to:<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="/css/form.css" /><![endif]-->
//注册JS文件,
Unit::jsFile(&#39;/js/jquery.lazyload.js&#39;);
//result to:<script src="/js/jquery.lazyload.js">
//IE9下加载JS文件
Unit::jsFile(&#39;/js/common.js&#39;, CClientScript::POS_HEAD, array(&#39;media&#39; => &#39;lt IE 9&#39;));
//result to:<--[if lt IE 9]><script src="/js/common.js"><![endif]-->
?>
Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.

For more Yii installation EClientScript plug-in extension to implement css, js file code compression and merging loading function, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)