Skip to content

Instantly share code, notes, and snippets.

@james2doyle
Last active May 5, 2025 17:50
Show Gist options
  • Save james2doyle/3aa8d1802db63cca84858bda9bd61e39 to your computer and use it in GitHub Desktop.
Save james2doyle/3aa8d1802db63cca84858bda9bd61e39 to your computer and use it in GitHub Desktop.
Use the Vite facade in Laravel to version the assets with a query string
<?php
// version the asset path for each deploy
Vite::createAssetPathsUsing(function (string $path): string {
return cache()->rememberForever($path, function () use ($path) {
// "z" is "day of the year" so this value will only change on the day of deployment
return sprintf('%s?v=%s', asset($path), date('z'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment