@@ -282,7 +282,9 @@ public function addCss($asset, $priority = null, $pipeline = true, $group = null
282
282
return $ this ;
283
283
}
284
284
285
+ $ modified = 0 ;
285
286
if (!$ this ->isRemoteLink ($ asset )) {
287
+ $ modified = $ this ->getLastModificationTime ($ asset );
286
288
$ asset = $ this ->buildLocalLink ($ asset );
287
289
}
288
290
@@ -295,8 +297,9 @@ public function addCss($asset, $priority = null, $pipeline = true, $group = null
295
297
'asset ' => $ asset ,
296
298
'priority ' => intval ($ priority ?: 10 ),
297
299
'order ' => count ($ this ->css ),
298
- 'pipeline ' => (bool )$ pipeline ,
299
- 'group ' => $ group ?: 'head '
300
+ 'pipeline ' => (bool ) $ pipeline ,
301
+ 'group ' => $ group ?: 'head ' ,
302
+ 'modified ' => $ modified
300
303
];
301
304
302
305
// check for dynamic array and merge with defaults
@@ -343,7 +346,9 @@ public function addJs($asset, $priority = null, $pipeline = true, $loading = nul
343
346
return $ this ;
344
347
}
345
348
349
+ $ modified = 0 ;
346
350
if (!$ this ->isRemoteLink ($ asset )) {
351
+ $ modified = $ this ->getLastModificationTime ($ asset );
347
352
$ asset = $ this ->buildLocalLink ($ asset );
348
353
}
349
354
@@ -356,9 +361,10 @@ public function addJs($asset, $priority = null, $pipeline = true, $loading = nul
356
361
'asset ' => $ asset ,
357
362
'priority ' => intval ($ priority ?: 10 ),
358
363
'order ' => count ($ this ->js ),
359
- 'pipeline ' => (bool )$ pipeline ,
364
+ 'pipeline ' => (bool ) $ pipeline ,
360
365
'loading ' => $ loading ?: '' ,
361
- 'group ' => $ group ?: 'head '
366
+ 'group ' => $ group ?: 'head ' ,
367
+ 'modified ' => $ modified
362
368
];
363
369
364
370
// check for dynamic array and merge with defaults
@@ -671,14 +677,11 @@ protected function pipelineCss($group = 'head')
671
677
// temporary list of assets to pipeline
672
678
$ temp_css = [];
673
679
674
- /** @var Cache $cache */
675
- $ cache = Grav::instance ()['cache ' ];
676
-
677
680
// clear no-pipeline assets lists
678
681
$ this ->css_no_pipeline = [];
679
682
680
683
// Compute uid based on assets and timestamp
681
- $ uid = md5 (json_encode ($ this ->css ) . $ this ->css_minify . $ this ->css_rewrite . $ group . $ cache -> getKey () );
684
+ $ uid = md5 (json_encode ($ this ->css ) . $ this ->css_minify . $ this ->css_rewrite . $ group );
682
685
$ file = $ uid . '.css ' ;
683
686
$ inline_file = $ uid . '-inline.css ' ;
684
687
@@ -756,14 +759,11 @@ protected function pipelineJs($group = 'head')
756
759
// temporary list of assets to pipeline
757
760
$ temp_js = [];
758
761
759
- /** @var Cache $cache */
760
- $ cache = Grav::instance ()['cache ' ];
761
-
762
762
// clear no-pipeline assets lists
763
763
$ this ->js_no_pipeline = [];
764
764
765
765
// Compute uid based on assets and timestamp
766
- $ uid = md5 (json_encode ($ this ->js ) . $ this ->js_minify . $ group . $ cache -> getKey () );
766
+ $ uid = md5 (json_encode ($ this ->js ) . $ this ->js_minify . $ group );
767
767
$ file = $ uid . '.js ' ;
768
768
$ inline_file = $ uid . '-inline.js ' ;
769
769
@@ -1100,18 +1100,37 @@ protected function isRemoteLink($link)
1100
1100
/**
1101
1101
* Build local links including grav asset shortcodes
1102
1102
*
1103
- * @param string $asset the asset string reference
1103
+ * @param string $asset the asset string reference
1104
+ * @param bool $absolute build absolute asset link
1104
1105
*
1105
- * @return string the final link url to the asset
1106
+ * @return string the final link url to the asset
1106
1107
*/
1107
- protected function buildLocalLink ($ asset )
1108
+ protected function buildLocalLink ($ asset, $ absolute = false )
1108
1109
{
1109
1110
try {
1110
- $ asset = Grav::instance ()['locator ' ]->findResource ($ asset , false );
1111
+ $ asset = Grav::instance ()['locator ' ]->findResource ($ asset , $ absolute );
1111
1112
} catch (\Exception $ e ) {
1112
1113
}
1113
1114
1114
- return $ asset ? $ this ->base_url . ltrim ($ asset , '/ ' ) : false ;
1115
+ $ uri = $ absolute ? $ asset : $ this ->base_url . ltrim ($ asset , '/ ' );
1116
+ return $ asset ? $ uri : false ;
1117
+ }
1118
+
1119
+ /**
1120
+ * Get the last modification time of asset
1121
+ *
1122
+ * @param string $asset the asset string reference
1123
+ *
1124
+ * @return string the last modifcation time or false on error
1125
+ */
1126
+ protected function getLastModificationTime ($ asset )
1127
+ {
1128
+ $ file = GRAV_ROOT . $ asset ;
1129
+ if (Grav::instance ()['locator ' ]->isStream ($ asset )) {
1130
+ $ file = $ this ->buildLocalLink ($ asset , true );
1131
+ }
1132
+
1133
+ return file_exists ($ file ) ? filemtime ($ file ) : false ;
1115
1134
}
1116
1135
1117
1136
/**
0 commit comments