Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mxdvl/d8387d95d438780a570700a8fd006a3e to your computer and use it in GitHub Desktop.
Save mxdvl/d8387d95d438780a570700a8fd006a3e to your computer and use it in GitHub Desktop.
Rewrite filename-based cache busting URIs (e.g. jquery.1476809927.js) to the correct filename in Laravel Valet
<?php
class CacheBustingKirbyValetDriver extends KirbyValetDriver
{
public function isStaticFile($sitePath, $siteName, $uri)
{
$result = parent::isStaticFile($sitePath, $siteName, $uri);
if ($result !== false) {
return $result;
}
if (preg_match('/(.+)\.(?:\d+)\.(js|css|png|jpg|jpeg|gif|svg|mp3|mp4|ogg)$/i', $uri, $matches)) {
// Rewrite cache busted URIs to their original filename (e.g. jquery.1476809927.js to jquery.js)
return $sitePath.$matches[1].'.'.$matches[2];
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment