Browse Source

cleanup cached js and css

tinect 5 years ago
parent
commit
74244c7d0a
3 changed files with 20 additions and 0 deletions
  1. 1 0
      data/web/inc/footer.inc.php
  2. 18 0
      data/web/inc/functions.inc.php
  3. 1 0
      data/web/inc/header.inc.php

+ 1 - 0
data/web/inc/footer.inc.php

@@ -9,6 +9,7 @@ logger();
         echo file_get_contents($JSPath);
     } else {
         echo $js_minifier->minify($JSPath);
+        cleanupCSS($css_minifier->getDataHash());
     }
     ?></script>
 <script>

+ 18 - 0
data/web/inc/functions.inc.php

@@ -1612,4 +1612,22 @@ function solr_status() {
   }
   return false;
 }
+
+function cleanupJS($ignore = '', $folder = '/tmp/*.js') {
+    foreach (glob($folder) as $filename) {
+        if(strpos($filename, $ignore) !== false) {
+            continue;
+        }
+        unlink($filename);
+    }
+}
+
+function cleanupCSS($ignore = '', $folder = '/tmp/*.css') {
+    foreach (glob($folder) as $filename) {
+        if(strpos($filename, $ignore) !== false) {
+            continue;
+        }
+        unlink($filename);
+    }
+}
 ?>

+ 1 - 0
data/web/inc/header.inc.php

@@ -36,6 +36,7 @@
           echo file_get_contents($CSSPath);
       } else {
           echo $css_minifier->minify($CSSPath);
+          cleanupCSS($css_minifier->getDataHash());
       }
       ?></style>
   <?php if (strtolower(trim($DEFAULT_THEME)) != "lumen"): ?>