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; }