<?php /* * All requests on *.js files will be redirected to this file. This is inteded * to create a minified js file instead of delivering the original js file, * which usually is 50% size bigger than the minified. * Creation of the minified js file will only occur if the main js file has * changed since last minification. * * Felix Honer * 2015/01/23 */ require "../config.php"; require "../core/frontend.php"; // name of the original js file (and also the requested file name) $jsfile = BASEDIR . "js/" . $_GET['filename'] . ".js"; // name of the minified js file $minJsfile = BASEDIR . "js/" . str_replace(".js", ".min.js", $_GET['filename'] . ".js"); if (!file_exists($minJsfile) || filemtime($jsfile) > filemtime($minJsfile)) { $js = frontend::minifyJs(file_get_contents($jsfile)); // invoke minifier framework file_put_contents($minJsfile, $js); // create file } header('Content-Type: application/javascript'); // some http headers header('Content-Length: ' . filesize($minJsfile)); print file_get_contents($minJsfile); // print output