Skip to content

Commit

Permalink
Merge pull request #120 from Laravel-Backpack/hot-fix/only-add-the-ca…
Browse files Browse the repository at this point in the history
…che-busting-string-to-non-internal-files

[HOT-FIX] only add the cache busting string to non internal files
  • Loading branch information
pxpm authored Apr 12, 2024
2 parents 3f2e7c9 + 2197834 commit fafa170
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Helpers/FileOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
class FileOutput
{
private string|null $nonce;

private string $cachebusting;

private bool $useRelativePaths = true;

private array $templates = [];

public function __construct()
Expand Down Expand Up @@ -67,7 +70,12 @@ public function write(string $path, array $attributes = []): void
*/
public function assetPath(string $path): string
{
$asset = Str::of(asset($path.$this->cachebusting));
// if path is not a url or it's local url, we will append the cachebusting
if (! Str::startsWith($path, ['http://', 'https://', '://']) || Str::startsWith($path, url(''))) {
$path .= $this->cachebusting;
}

$asset = Str::of(asset($path));

if ($this->useRelativePaths && $asset->startsWith(url(''))) {
$asset = $asset->after('//')->after('/')->start('/');
Expand Down

0 comments on commit fafa170

Please sign in to comment.