Same name and namespace in other branches
  1. 7.x-2.x advagg_js_compress/advagg_js_compress.advagg.inc \advagg_js_compress_jsminplus() 1 commentaire

Compress a JS string using jsmin+

Paramètres

$contents: Javascript string.

Return value

array with the size before and after.

3 calls to advagg_js_compress_jsminplus()
advagg_js_compress_advagg_js_inline_alter dans advagg_js_compress/advagg_js_compress.module
Implements hook_advagg_js_inline_alter().
advagg_js_compress_prep dans advagg_js_compress/advagg_js_compress.module
Compress a JS string
advagg_js_compress_test_file dans advagg_js_compress/advagg_js_compress.module
Run various theme functions so the cache is primed.

Fichier

advagg_js_compress/advagg_js_compress.module, line 278

Code

function advagg_js_compress_jsminplus(&$contents) {
    // Try to allocate enough time to run JSMin+.
    if (function_exists('set_time_limit')) {
        @set_time_limit(240);
    }
    // JSMin+ the contents of the aggregated file.
    require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'advagg_js_compress') . '/jsminplus.inc';
    // Strip Byte Order Marks (BOM's) from the file, JSMin+ cannot parse these.
    $before = strlen($contents);
    $original_contents = $contents;
    try {
        $contents = str_replace(pack("CCC", 0xef, 0xbb, 0xbf), "", $contents);
        ob_start();
        $contents = JSMinPlus::minify($contents);
        $error = trim(ob_get_contents());
        if (!empty($error)) {
            throw new Exception($error);
        }
        $after = strlen($contents);
    } catch (Exception $e) {
        // Log the exception thrown by JSMin+ and roll back to uncompressed content.
        watchdog('advagg', $e->getMessage() . '<pre>' . $original_contents . '</pre>', NULL, WATCHDOG_WARNING);
        $contents = $original_contents;
        $after = $before;
    }
    ob_end_clean();
    return array(
        $before,
        $after,
    );
}