. /** * JS and CSS compression. * * @package core * @copyright 2013 Petr Skoda {@link http://skodak.org} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Collection of JS and CSS compression methods. */ class core_minify { /** * Minify JS code. * * @param string $content * @return string minified JS code */ public static function js($content) { global $CFG; require_once("$CFG->libdir/minify/lib/JSMinPlus.php"); try { ob_start(); // JSMinPlus just echos errors, weird... $compressed = JSMinPlus::minify($content); if ($compressed !== false) { ob_end_clean(); return $compressed; } $error = ob_get_clean(); } catch (Exception $e) { ob_end_clean(); $error = $e->getMessage(); } $return = <<libdir/minify/lib/Minify/CSS/Compressor.php"); $error = 'unknown'; try { $compressed = Minify_CSS_Compressor::process($content); if ($compressed !== false) { return $compressed; } } catch (Exception $e) { $error = $e->getMessage(); } $return = <<