Пример #1
0
/**
 * @internal Performs JavaScript minifying
 */
function minify_js($paths, $target_file)
{
    require_once __DIR__ . "/minify/jsmin.php";
    $files = minify_collect_files($paths, 'js');
    log_debug("JS files to minify: ", $files);
    //die("stopped");
    $code = "";
    foreach ($files as $f) {
        if (starts_with($f, "/") && !starts_with($f, "//")) {
            $f = (isSSL() ? "https" : "http") . "://{$_SERVER['SERVER_NAME']}" . $f;
        }
        $js = sendHTTPRequest($f, false, false, $response_header);
        if (mb_detect_encoding($js) != "UTF-8") {
            $js = mb_convert_encoding($js, "UTF-8");
        }
        if (stripos($response_header, "404 Not Found") !== false) {
            continue;
        }
        $js = "/* FILE: {$f} */\n{$js}";
        if (!isset($GLOBALS['nominify'])) {
            try {
                $code .= jsmin::minify($js) . "\n";
            } catch (Exception $ex) {
                WdfException::Log("EXCEPTION occured in jsmin::minify ({$js})", $ex);
                $code .= $js . "\n";
            }
        } else {
            $code .= $js . "\n";
        }
    }
    global $ext_resources;
    foreach (array_unique($ext_resources) as $ext) {
        $code .= "\$.getScript('{$ext}', function(){ wdf.debug('external script loaded:','{$ext}'); });";
    }
    file_put_contents($target_file, $code);
}
Пример #2
0
 /**
  * Compresses using the the basic JSMin compressor
  *
  * @return void
  * @author Jonathan Geiger
  **/
 protected function compress_jsmin($file)
 {
     include_once Kohana::find_file('vendor', 'jsmin/jsmin-1.1.1');
     // Pretty simple, actually
     file_put_contents($file, jsmin::minify(file_get_contents($file)));
 }