summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-03-18 11:00:44 +0400
committerAndrew Dolgov <[email protected]>2013-03-18 11:00:44 +0400
commitc670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (patch)
tree69b562eb609b4a7ef3ed95138c9f5b6d91896a52
parent107997e6cb04f5daddb11e631b9866c385f2ca7d (diff)
cache minified js files
-rw-r--r--cache/js/.empty0
-rw-r--r--include/functions.php28
-rw-r--r--include/sanity_check.php4
-rw-r--r--index.php10
-rw-r--r--prefs.php9
5 files changed, 37 insertions, 14 deletions
diff --git a/cache/js/.empty b/cache/js/.empty
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/cache/js/.empty
diff --git a/include/functions.php b/include/functions.php
index b43fda3a1..8c2ced801 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -3907,4 +3907,32 @@
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;
+ }
+
?>
diff --git a/include/sanity_check.php b/include/sanity_check.php
index fcf548705..4925486a3 100644
--- a/include/sanity_check.php
+++ b/include/sanity_check.php
@@ -36,6 +36,10 @@
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");
diff --git a/index.php b/index.php
index 49fcfdf98..68d6fc753 100644
--- a/index.php
+++ b/index.php
@@ -95,13 +95,9 @@
}
}
- 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>
diff --git a/prefs.php b/prefs.php
index 4027fd1fa..a47d00bce 100644
--- a/prefs.php
+++ b/prefs.php
@@ -54,13 +54,8 @@
}
}
- 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>