88use BadMethodCallException ;
99use Hyde \Support \Models \Route ;
1010use Hyde \Foundation \HydeKernel ;
11+ use Hyde \Support \Filesystem \MediaFile ;
1112use Hyde \Framework \Exceptions \FileNotFoundException ;
1213use Illuminate \Support \Str ;
1314
@@ -99,7 +100,7 @@ public function mediaLink(string $destination, bool $validate = false): string
99100 throw new FileNotFoundException ($ sourcePath );
100101 }
101102
102- return $ this ->relativeLink ("{$ this ->kernel ->getMediaOutputDirectory ()}/ $ destination " );
103+ return $ this ->withCacheBusting ( $ this -> relativeLink ("{$ this ->kernel ->getMediaOutputDirectory ()}/ $ destination " ), $ destination );
103104 }
104105
105106 /**
@@ -117,10 +118,10 @@ public function asset(string $name): string
117118 $ name = Str::start ($ name , "{$ this ->kernel ->getMediaOutputDirectory ()}/ " );
118119
119120 if ($ this ->hasSiteUrl ()) {
120- return $ this ->url ($ name );
121+ return $ this ->withCacheBusting ( $ this -> url ($ name ), $ name );
121122 }
122123
123- return $ this ->relativeLink ($ name );
124+ return $ this ->withCacheBusting ( $ this -> relativeLink ($ name ), $ name );
124125 }
125126
126127 /**
@@ -180,4 +181,12 @@ public static function isRemote(string $url): bool
180181 {
181182 return str_starts_with ($ url , 'http ' ) || str_starts_with ($ url , '// ' );
182183 }
184+
185+ /**
186+ * Apply cache to the URL if enabled in the configuration.
187+ */
188+ protected function withCacheBusting (string $ url , string $ file ): string
189+ {
190+ return $ url .MediaFile::getCacheBustKey ($ file );
191+ }
183192}
0 commit comments