Skip to content

Commit 94112c0

Browse files
committed
Extract helper method to perform cache busting
1 parent 3b57fe8 commit 94112c0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/framework/src/Foundation/Kernel/Hyperlinks.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function mediaLink(string $destination, bool $validate = false): string
100100
throw new FileNotFoundException($sourcePath);
101101
}
102102

103-
return $this->relativeLink("{$this->kernel->getMediaOutputDirectory()}/$destination").MediaFile::getCacheBustKey($destination);
103+
return $this->withCacheBusting($this->relativeLink("{$this->kernel->getMediaOutputDirectory()}/$destination"), $destination);
104104
}
105105

106106
/**
@@ -118,10 +118,10 @@ public function asset(string $name): string
118118
$name = Str::start($name, "{$this->kernel->getMediaOutputDirectory()}/");
119119

120120
if ($this->hasSiteUrl()) {
121-
return $this->url($name).MediaFile::getCacheBustKey($name);
121+
return $this->withCacheBusting($this->url($name), $name);
122122
}
123123

124-
return $this->relativeLink($name).MediaFile::getCacheBustKey($name);
124+
return $this->withCacheBusting($this->relativeLink($name), $name);
125125
}
126126

127127
/**
@@ -181,4 +181,12 @@ public static function isRemote(string $url): bool
181181
{
182182
return str_starts_with($url, 'http') || str_starts_with($url, '//');
183183
}
184+
185+
/**
186+
* Apply cache to the URL if enabled in the configuration.
187+
*/
188+
protected function addCacheBustKey(string $url, string $file): string
189+
{
190+
return $url.MediaFile::getCacheBustKey($file);
191+
}
184192
}

0 commit comments

Comments
 (0)