]> git.wh0rd.org Git - tt-rss.git/commitdiff
get_minified_js: store and check tt-rss version in cached files
authorAndrew Dolgov <noreply@fakecake.org>
Tue, 19 Aug 2014 10:50:25 +0000 (14:50 +0400)
committerAndrew Dolgov <noreply@fakecake.org>
Tue, 19 Aug 2014 10:50:25 +0000 (14:50 +0400)
include/functions2.php

index 07024d38fadf00cfaf924f73b36bdd73b25d7679..9d8bc76aad7493dadff1ab6347b88aa97be068d0 100644 (file)
                        if (!isset($_GET['debug'])) {
                                $cached_file = CACHE_DIR . "/js/".basename($js).".js";
 
-                               if (file_exists($cached_file) &&
-                                               is_readable($cached_file) &&
-                                               filemtime($cached_file) >= filemtime("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);
+                                       list($header, $contents) = explode("\n", file_get_contents($cached_file), 2);
 
-                               } else {
-                                       $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js"));
-                                       file_put_contents($cached_file, $minified);
-                                       $rv .= $minified;
+                                       if ($header && $contents) {
+                                               list($htag, $hversion) = explode(":", $header);
+
+                                               if ($htag == "tt-rss" && $hversion == VERSION) {
+                                                       $rv .= $contents;
+                                                       continue;
+                                               }
+                                       }
                                }
+
+                               $minified = JShrink\Minifier::minify(file_get_contents("js/$js.js"));
+                               file_put_contents($cached_file, "tt-rss:" . VERSION . "\n" . $minified);
+                               $rv .= $minified;
+
                        } else {
-                               $rv .= file_get_contents("js/$js.js");
+                               $rv .= file_get_contents("js/$js.js"); // no cache in debug mode
                        }
                }