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

YUI Compressor在线压缩(Javascript/Css)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 19:39:48
Original
1281 people have browsed it

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;
    }
Copy after login

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template