php教程 PHP开发 Yii는 CSS 및 js 파일 코드 압축 및 병합 로딩 기능을 구현하기 위해 EClientScript 플러그인 확장을 설치합니다.

Yii는 CSS 및 js 파일 코드 압축 및 병합 로딩 기능을 구현하기 위해 EClientScript 플러그인 확장을 설치합니다.

Dec 30, 2016 pm 04:24 PM

이 기사의 예에서는 Yii에 EClientScript 플러그인 확장을 설치하여 CSS와 js 파일의 코드 압축 및 병합 로딩 기능을 구현하는 방법을 설명합니다. 참고용으로 모든 사람과 공유하세요. 자세한 내용은 다음과 같습니다.

확장 플러그인 다운로드 주소, 압축을 풀고 /protected/vendor/에 복사

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

기본 구성 파일은 플러그인을 구성하고

//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
),
로그인 후 복사

도구 클래스 Unit.php를 구성 요소에 추가한 후 /protected/vendor/comComponents에 배치합니다.

/**
 * 注册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);
}
로그인 후 복사

템플릿은 css 파일과 js 파일을 호출합니다

<?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]-->
?>
로그인 후 복사

이 기사가 Yii를 기반으로 하는 모든 사람의 PHP 프로그램 설계에 도움이 되기를 바랍니다. 뼈대.

Css, js 파일 코드 압축 및 병합 로딩 기능을 구현하는 Yii 설치 EClientScript 플러그인 확장에 대한 자세한 내용은 PHP 중국어 웹사이트를 참고하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)