Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rewrite filename-based cache busting URIs (e.g. jquery.1476809927.js) to the correct filename in Laravel Valet
<?php
class CacheBustingLaravelValetDriver extends LaravelValetDriver
{
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)$/i', $uri, $matches)) {
// Rewrite cache busted URIs to their original filename (e.g. jquery.1476809927.js to jquery.js)
return $sitePath.'/public'.$matches[1].'.'.$matches[2];
}
return false;
}
}
@mxdvl

This comment has been minimized.

Copy link

@mxdvl mxdvl commented Aug 2, 2018

Thank you! I’ve used this script as a basis for a Kirby driver, and added (svg|mp4|ogg|webm) to the regex!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.