]> git.wh0rd.org - tt-rss.git/commitdiff
cache minified js files
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 18 Mar 2013 07:00:44 +0000 (11:00 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 18 Mar 2013 07:00:44 +0000 (11:00 +0400)
cache/js/.empty [new file with mode: 0644]
include/functions.php
include/sanity_check.php
index.php
prefs.php

diff --git a/cache/js/.empty b/cache/js/.empty
new file mode 100644 (file)
index 0000000..e69de29
index b43fda3a14672469f264083e6a0be361f149a40c..8c2ced801d6469b6caaaf538cb9aa3eb9c0612e1 100644 (file)
                return in_array($interface, class_implements($class));
        }
 
+       function get_minified_js($files) {
+               require_once 'lib/jshrink/Minifier.php';
+
+               $rv = '';
+
+               foreach ($files as $js) {
+                       if (!isset($_GET['debug'])) {
+                               $cached_file = CACHE_DIR . "/js/$js.js";
+
+                               if (file_exists($cached_file) &&
+                                               is_readable($cached_file) &&
+                                               filemtime($cached_file) >= filemtime("js/$js.js")) {
+
+                                       $rv .= file_get_contents($cached_file);
+
+                               } else {
+                                       $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js"));
+                                       file_put_contents($cached_file, $minified);
+                                       $rv .= $minified;
+                               }
+                       } else {
+                               $rv .= file_get_contents("js/$js.js");
+                       }
+               }
+
+               return $rv;
+       }
+
 ?>
index fcf5487055206791cdb782619cc3dad8f6b3e797..4925486a36dc780f10d5337e7ce073ed355c934d 100644 (file)
                                array_push($errors, "Data export cache is not writable (chmod -R 777 ".CACHE_DIR."/export)");
                        }
 
+                       if (!is_writable(CACHE_DIR . "/js")) {
+                               array_push($errors, "Javascript cache is not writable (chmod -R 777 ".CACHE_DIR."/js)");
+                       }
+
                        if (GENERATED_CONFIG_CHECK != EXPECTED_CONFIG_VERSION) {
                                array_push($errors,
                                        "Configuration option checker sanity_config.php is outdated, please recreate it using ./utils/regen_config_checks.sh");
index 49fcfdf988cadaabf7e217f8e6aaab6276fbb295..68d6fc753eef0c63d1ab92f512eb5efa47aa257e 100644 (file)
--- a/index.php
+++ b/index.php
                        }
                }
 
-               foreach (array("tt-rss", "functions", "feedlist", "viewfeed", "FeedTree") as $js) {
-                       if (!isset($_GET['debug'])) {
-                               echo JShrink\Minifier::minify(file_get_contents("js/$js.js"));
-                       } else {
-                               echo file_get_contents("js/$js.js");
-                       }
-               }
+               print get_minified_js(array("tt-rss",
+                       "functions", "feedlist", "viewfeed", "FeedTree"));
+
        ?>
        </script>
 
index 4027fd1faded09e0f3f4a397aec409ccb7f3a73c..a47d00bce29416fd2d6421b2aaa5dd4818a58932 100644 (file)
--- a/prefs.php
+++ b/prefs.php
                        }
                }
 
-               foreach (array("functions", "deprecated", "prefs") as $js) {
-                       if (!isset($_GET['debug'])) {
-                               echo JShrink\Minifier::minify(file_get_contents("js/$js.js"));
-                       } else {
-                               echo file_get_contents("js/$js.js");
-                       }
-               }
+               print get_minified_js(array("functions", "deprecated", "prefs"));
+
        ?>
        </script>