88use BadMethodCallException ;
99use Hyde \Support \Models \Route ;
1010use Hyde \Foundation \HydeKernel ;
11+ use Hyde \Support \Filesystem \MediaFile ;
1112use Illuminate \Support \Str ;
1213
1314use function str_ends_with ;
@@ -92,7 +93,7 @@ public function relativeLink(string $destination): string
9293 */
9394 public function mediaLink (string $ destination ): string
9495 {
95- return $ this ->relativeLink ("{$ this ->kernel ->getMediaOutputDirectory ()}/ $ destination " );
96+ return $ this ->withCacheBusting ( $ this -> relativeLink ("{$ this ->kernel ->getMediaOutputDirectory ()}/ $ destination " ) );
9697 }
9798
9899 /**
@@ -110,10 +111,10 @@ public function asset(string $name): string
110111 $ name = Str::start ($ name , "{$ this ->kernel ->getMediaOutputDirectory ()}/ " );
111112
112113 if ($ this ->hasSiteUrl ()) {
113- return $ this ->url ($ name );
114+ return $ this ->withCacheBusting ( $ this -> url ($ name ), $ name );
114115 }
115116
116- return $ this ->relativeLink ($ name );
117+ return $ this ->withCacheBusting ( $ this -> relativeLink ($ name ), $ name );
117118 }
118119
119120 /**
@@ -173,4 +174,12 @@ public static function isRemote(string $url): bool
173174 {
174175 return str_starts_with ($ url , 'http ' ) || str_starts_with ($ url , '// ' );
175176 }
177+
178+ /**
179+ * Apply cache to the URL if enabled in the configuration.
180+ */
181+ protected function withCacheBusting (string $ url , string $ file ): string
182+ {
183+ return $ url .MediaFile::getCacheBustKey ($ file );
184+ }
176185}
0 commit comments