


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 ),
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); }
template Calling css files and js files
<?php //注册CSS文件, Unit::cssFile('/css/home/base.css'); //result to:<link rel="stylesheet" type="text/css" href="/css/home/base.css" /> //IE6下加载CSS文件 Unit::cssFile('/css/form.css','lte IE 6'); //result to:<!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="/css/form.css" /><![endif]--> //注册JS文件, Unit::jsFile('/js/jquery.lazyload.js'); //result to:<script src="/js/jquery.lazyload.js"> //IE9下加载JS文件 Unit::jsFile('/js/common.js', CClientScript::POS_HEAD, array('media' => 'lt IE 9')); //result to:<--[if lt IE 9]><script src="/js/common.js"><![endif]--> ?>
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
