dt4320279 2012-04-24 06:39
浏览 94

如何在YUI压缩器中使用Minify PHP?

I would like to use YUI compressor with minify PHP rather than the default JSmin. Does anyone have experience setting this up?

Right now I am using the groupsConfig.php to combine the JS.

return array(
    'jsAll'  => array('//contenido/themes/bam/assets/js/jquery.js', '//contenido/themes/bam/assets/js/modernizr.js','//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/imgpreload.js', '//contenido/themes/bam/assets/js/history.js','//contenido/themes/bam/assets/js/ajaxify.js', '//contenido/themes/bam/assets/js/isotope.js'),
    'jsHome' => array('//contenido/themes/bam/assets/js/easing.js','//contenido/themes/bam/assets/js/scrollable.js', '//contenido/themes/bam/assets/js/home.js'),
    'cssAll' => array('//contenido/themes/bam/bam.css'),
);

As it says on the homepage:

Uses an enhanced port of Douglas Crockford's JSMin library and custom classes to minify CSS and HTML

I have the following code in config.php, but I get a 500 error when trying to view the combined js file:

function yuiJs($js) {
    require_once '/lib/Minify/YUICompressor.php'; 
    Minify_YUICompressor::$jarFile = '/lib/yuicompressor-2.4.2.jar'; 
    Minify_YUICompressor::$tempDir = '/temp'; 
    return Minify_YUICompressor::minifyJs($js); 
}
$min_serveOptions['minifiers']['application/x-javascript'] = 'yuiJs';

It also appears that there are several lines in lib/Minify/YUICompressor.php that need to be configured, and I'm not sure if I'm doing it right:

class Minify_YUICompressor {

    /**
     * Filepath of the YUI Compressor jar file. This must be set before
     * calling minifyJs() or minifyCss().
     *
     * @var string
     */
    public static $jarFile = '../yuicompressor-2.4.2.jar';

    /**
     * Writable temp directory. This must be set before calling minifyJs()
     * or minifyCss().
     *
     * @var string
     */
    public static $tempDir = '../../temp/';

    /**
     * Filepath of "java" executable (may be needed if not in shell's PATH)
     *
     * @var string
     */
    public static $javaExecutable = 'java';
  • 写回答

1条回答 默认 最新

  • dongwo7858 2013-01-03 06:36
    关注

    I had the same problem on windows. It seems jar file needs to be executable in order to run yui compressor. So, i have to remove excutable check from YUICompressor.php

    #132 
    
    
    private static function _prepare()
        {
            if (! is_file(self::$jarFile)) {
                throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not a valid file.');
            }
    //         if (! is_executable(self::$jarFile)) {
    //             throw new Exception('Minify_YUICompressor : $jarFile('.self::$jarFile.') is not executable.');
    //         }
            if (! is_dir(self::$tempDir)) {
                throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not a valid direcotry.');
            }
            if (! is_writable(self::$tempDir)) {
                throw new Exception('Minify_YUICompressor : $tempDir('.self::$tempDir.') is not writable.');
            }
        }
    

    and that works fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog