@@ -24,6 +24,7 @@ class Spriter {
2424 protected $ eachTemplate ;
2525 protected $ eachHoverTemplate ;
2626 protected $ ratioTemplate ;
27+ protected $ timestamp ;
2728 protected $ forceGenerate = false ;
2829 protected $ ignoreHover = false ;
2930 protected $ hoverSuffix = "-hover " ;
@@ -49,6 +50,7 @@ public function __construct( $config = array() ) {
4950 // setup & generation
5051 $ this ->setupIcons ();
5152 if ( $ this ->hasChanged () || $ this ->forceGenerate ) {
53+ $ this ->timestamp = date ( 'YmdHis ' , time () );
5254 $ this ->generateChecksum ();
5355 $ this ->generateSprite ();
5456 $ this ->generateCSS ();
@@ -105,6 +107,15 @@ private function hasChanged() {
105107 return true ;
106108 }
107109 }
110+
111+ // Check if the generated css file exists
112+ foreach ( $ this ->targets as $ target ) {
113+ if ( !file_exists ( $ target ['cssDirectory ' ] . "/ " . $ target ['cssFilename ' ] ) ) {
114+ return true ;
115+ }
116+ }
117+
118+ // Checksum comparison
108119 if ( file_exists ( __DIR__ . "/ " . $ this ->getChecksumName () ) ) {
109120 $ lastChecksum = file_get_contents ( __DIR__ . "/ " . $ this ->getChecksumName () );
110121
@@ -115,12 +126,6 @@ private function hasChanged() {
115126 else {
116127 return true ;
117128 }
118- // Check if the generated css file exists
119- foreach ( $ this ->targets as $ target ) {
120- if ( !file_exists ( $ target ['cssDirectory ' ] . "/ " . $ target ['cssFilename ' ] ) ) {
121- return true ;
122- }
123- }
124129
125130 return false ;
126131 }
@@ -317,13 +322,16 @@ private function generateCSS() {
317322 $ result = "" ;
318323
319324 $ replacements = array (
320- "{{spriteDirectory}} " => $ this ->spriteFilepath , // deprecated
321325 "{{spriteFilepath}} " => $ this ->spriteFilepath ,
322326 "{{spriteFilename}} " => $ this ->spriteFilename ,
323- "{{sprite}} " => $ this ->spriteFilepath . "/ " . $ this ->spriteFilename . ".png " ,
324- "{{namespace}} " => $ this ->namespace ,
327+ "{{sprite}} " => $ this ->spriteFilepath . "/ " . $ this ->spriteFilename . ".png? " . $ this ->timestamp ,
325328 "{{width}} " => $ this ->width . "px " ,
326- "{{height}} " => $ this ->height . "px "
329+ "{{height}} " => $ this ->height . "px " ,
330+ "{{namespace}} " => $ this ->namespace ,
331+ "{{checksum}} " => $ this ->spriteChecksum ,
332+ "{{timestamp}} " => $ this ->timestamp ,
333+
334+ "{{spriteDirectory}} " => $ this ->spriteFilepath // deprecated
327335 );
328336
329337 $ result .= str_replace (
@@ -344,16 +352,19 @@ private function generateCSS() {
344352 foreach ( $ this ->retina as $ ratio ) {
345353 if ( $ ratio > 1 ) {
346354 $ replacements = array (
347- "{{spriteDirectory}} " => $ this ->spriteFilepath , // deprecated
348355 "{{spriteFilepath}} " => $ this ->spriteFilepath ,
349356 "{{spriteFilename}} " => $ this ->spriteFilename ,
350- "{{sprite}} " => $ this ->spriteFilepath . "/ " . $ this ->spriteFilename . $ this ->retinaDelimiter . $ ratio . "x.png " ,
351- "{{namespace}} " => $ this ->namespace ,
357+ "{{sprite}} " => $ this ->spriteFilepath . "/ " . $ this ->spriteFilename . $ this ->retinaDelimiter . $ ratio . "x.png? " . $ this ->timestamp ,
352358 "{{ratio}} " => $ ratio ,
353359 "{{ratioFrag}} " => $ ratio . "/1 " ,
354360 "{{width}} " => $ this ->width . "px " ,
355361 "{{height}} " => $ this ->height . "px " ,
356- "{{delimiter}} " => $ this ->retinaDelimiter
362+ "{{delimiter}} " => $ this ->retinaDelimiter ,
363+ "{{namespace}} " => $ this ->namespace ,
364+ "{{checksum}} " => $ this ->spriteChecksum ,
365+ "{{timestamp}} " => $ this ->timestamp ,
366+
367+ "{{spriteDirectory}} " => $ this ->spriteFilepath , // deprecated
357368 );
358369 $ ratios = str_replace (
359370 array_keys ( $ replacements ),
0 commit comments