From 444f7ec9d18781585b3112fa9027963148061600 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 7 Sep 2011 17:08:57 -0400 Subject: [PATCH] Added javascript minification caching --- README.md | 3 ++- js.php | 24 +++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d69396c..5309b24 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,5 @@ A simple set of minifying scripts for CSS and Javascript 1. Figure out your file paths, and set them in css.php and js.php. 2. Add your css and javascript files to groups, in `config/css_groups.php` and `config/js_groups.php` respectively 3. Point your CSS links in your HTML to `css.php/g/[group_name]`, and likewise your javascript to `js.php/g/[group_name]` -4. Enjoy a faster loading website \ No newline at end of file +4. Add a folder named "cache" to your js path +5. Enjoy a faster loading website \ No newline at end of file diff --git a/js.php b/js.php index 2b1c2ae..c66e39e 100644 --- a/js.php +++ b/js.php @@ -1,6 +1,7 @@ false)); -} - $requested_time=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : time(); @@ -63,6 +67,16 @@ if($last_modified === $requested_time) exit(); } +if(!isset($_GET['debug']) && ($cache_modified < $last_modified)) +{ + $js = trim(JShrink::minify($js, array('flaggedComments' => false))); + file_put_contents($cache_file, $js); +} +else +{ + $js = file_get_contents($cache_file); +} + header("Content-Type: application/x-javascript; charset=utf8"); header("Cache-control: public, max-age=691200, must-revalidate"); header("Last-Modified: ".gmdate('D, d M Y H:i:s', $last_modified)." GMT");