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

YUI Compressor在线压缩(Javascript/Css)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
发布: 2016-06-06 19:39:48
原创
1294 人浏览过

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

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;

    }

登录后复制

相关标签:
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板