public static function minify($js, $options = array()) { try { ob_start(); $jshrink = new Minifier(); $js = $jshrink->lock($js); $jshrink->minifyDirectToOutput($js, $options); // Sometimes there's a leading new line, so we trim that out here. $js = ltrim(ob_get_clean()); $js = $jshrink->unlock($js); unset($jshrink); return $js; } catch (\Exception $e) { if (isset($jshrink)) { // Since the breakdownScript function probably wasn't finished // we clean it out before discarding it. $jshrink->clean(); unset($jshrink); } // without this call things get weird, with partially outputted js. ob_end_clean(); throw $e; } }