Remove comments from JavaScript.

Parameters

string $content: JS string to minify.

1 call to advagg_remove_js_comments()
advagg_does_js_start_with_use_strict in ./advagg.inc
Given a js string, see if "use strict"; is the first thing ran.

File

./advagg.inc, line 413

Code

function advagg_remove_js_comments(&$content) {
    // Remove comments.
    $content = preg_replace('/(?:(?:\\/\\*(?:[^*]|(?:\\*+[^*\\/]))*\\*+\\/)|(?:(?<!\\:|\\\\|\'|\\")\\/\\/.*))/', '', $content);
    // Remove space after colons.
    // Remove space before equal signs.
    // Remove space after equal signs.
    $content = str_replace(array(
        ': ',
        ' =',
        '= ',
    ), array(
        ':',
        '=',
        '=',
    ), $content);
    // Remove excessive whitespace.
    $content = str_replace(array(
        "\r\n\r\n",
        "\n\n",
        "\r\r",
        '\\t',
        '  ',
        '    ',
        '    ',
    ), '', $content);
}