Combining and Compressing multiple JavaScript files in php

前端 未结 5 1469
孤城傲影
孤城傲影 2020-12-05 01:07

I am working on a PHP app that requires eight javascript files (hello web2.0).

I am wondering what the best way combine and compress all of the files dynamically. A

5条回答
  •  既然无缘
    2020-12-05 01:51

     function compress($buffer) {
            /* remove comments */
            $buffer = preg_replace("/((?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:\/\/.*))/", "", $buffer);
            /* remove tabs, spaces, newlines, etc. */
            $buffer = str_replace(array("\r\n","\r","\t","\n",'  ','    ','     '), '', $buffer);
            /* remove other spaces before/after ) */
            $buffer = preg_replace(array('(( )+\))','(\)( )+)'), ')', $buffer);
            return $buffer;
        }
    

    Source: http://castlesblog.com/2010/august/14/php-javascript-css-minification

提交回复
热议问题