Heim > php教程 > php手册 > YUI Compressor在线压缩(Javascript/Css)

YUI Compressor在线压缩(Javascript/Css)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 19:39:48
Original
1284 Leute haben es durchsucht

demo地址:http://www.atool.org/yui.php 支持YUICompressor的所有功能和指令,支持Javascript/Css的在线压缩、混淆和合并文件,从而减少网站网络请求和连接数量。 支持多文件的压缩合并,但是请注意合并的文件属于同一种类型,js或css,不可混淆使用。 YUI

demo地址:http://www.atool.org/yui.php

支持YUI Compressor的所有功能和指令,支持Javascript/Css的在线压缩、混淆和合并文件,从而减少网站网络请求和连接数量。
支持多文件的压缩合并,但是请注意合并的文件属于同一种类型,js或css,不可混淆使用。

YUI Compressor

function compress()
    {
        
        // read the input
        foreach ($this->files as $file) {
    		$this->string .= file_get_contents($file) or die("Cannot read from uploaded file");        
        }
    	
        // create single file from all input
        $input_hash = sha1($this->string);
        $file = $this->TEMP_FILES_DIR . '/' . $input_hash . '.txt';
        $fh = fopen($file, 'w') or die("Can't create new file");
        fwrite($fh, $this->string);
        fclose($fh);
    	
    	// start with basic command
        $cmd = "java -Xmx32m -jar " . escapeshellarg($this->JAR_PATH) . ' ' . escapeshellarg($file) . " --charset UTF-8";
    
        // set the file type
    	$cmd .= " --type " . (strtolower($this->options['type']) == "css" ? "css" : "js");
    	
    	// and add options as needed
    	if ($this->options['linebreak'] && intval($this->options['linebreak']) > 0) {
            $cmd .= ' --line-break ' . intval($this->options['linebreak']);
    	}
    	if ($this->options['verbose']) {
    	   $cmd .= " -v";
        }
            
		if ($this->options['nomunge']) {
			$cmd .= ' --nomunge';
		}
		
		if ($this->options['semi']) {
			$cmd .= ' --preserve-semi';
		}
		
		if ($this->options['nooptimize']) {
			$cmd .= ' --disable-optimizations';
		}
    
        // execute the command
    	exec($cmd . ' 2>&1', $raw_output);
    	
    	// add line breaks to show errors in an intelligible manner
        $flattened_output = implode("\n", $raw_output);
    	
    	// clean up (remove temp file)
    	unlink($file);
    	
    	// return compressed output
    	return $flattened_output;
    }
Nach dem Login kopieren

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage