12
12
header ("Pragma: cache " );
13
13
header ("Cache-Control: max-age= $ seconds_to_cache " );
14
14
15
+ // Compile and cache LESS CSS file
16
+ function autoCompileLess ($ input , $ output ) {
17
+ $ inputFile = $ _SERVER ['DOCUMENT_ROOT ' ].$ input ;
18
+ $ outputFile = $ _SERVER ['DOCUMENT_ROOT ' ].$ output ;
19
+ $ cacheFile = $ inputFile .".cache " ;
20
+
21
+ if (file_exists ($ cacheFile )) {
22
+ $ cache = unserialize (file_get_contents ($ cacheFile ));
23
+ } else {
24
+ $ cache = $ inputFile ;
25
+ }
26
+
27
+ $ less = new lessc ;
28
+ $ newCache = $ less ->cachedCompile ($ cache );
29
+
30
+ if (!is_array ($ cache ) || $ newCache ["updated " ] > $ cache ["updated " ]) {
31
+ file_put_contents ($ cacheFile , serialize ($ newCache ));
32
+ file_put_contents ($ outputFile , $ newCache ['compiled ' ]);
33
+ }
34
+ }
35
+
36
+ autoCompileLess ('/assets/styles/less/styles.less ' , '/assets/styles/styles.css ' );
37
+
15
38
// Get modified file date
16
39
function getFiledate ($ file , $ format ) {
17
40
if (is_file ($ file )) {
@@ -33,7 +56,7 @@ function getFiledate($file, $format) {
33
56
// Add a script element as a child of the body
34
57
function downloadJSAtOnload() {
35
58
var element = document.createElement("script");
36
- element.src = "/assets/scripts/scripts.js?v= <?= getFiledate ('assets/scripts/scripts.js ' ,'YmdHis ' ); ?> ";
59
+ element.src = "/assets/scripts/scripts.<?= getFiledate ('assets/scripts/scripts.js ' ,'YmdHis ' ); ?> .js ";
37
60
document.body.appendChild(element);
38
61
}
39
62
@@ -47,7 +70,7 @@ function downloadJSAtOnload() {
47
70
}
48
71
</script>
49
72
50
- <link rel="stylesheet" href="/assets/styles/styles.css?v= <?= getFiledate ('assets/styles/styles.css ' ,'YmdHis ' ); ?> " />
73
+ <link rel="stylesheet" href="/assets/styles/styles.<?= getFiledate ('assets/styles/styles.css ' ,'YmdHis ' ); ?> .css " />
51
74
<link rel="icon" href="<?= url ('assets/images/favicon.png ' ) ?> " type="image/png"/>
52
75
<link rel="apple-touch-icon-precomposed" href="<?= url ('assets/images/apple-touch-icon.png ' ) ?> "/>
53
76
<link rel="license" href="<?= html ($ site ->licenseurl ) ?> "/>
0 commit comments