Forked from stidges/CacheBustingLaravelValetDriver.php
Last active
August 21, 2018 02:20
-
-
Save tannerhodges/a506fafc98c70539be6967d418baed88 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CustomWordPressValetDriver extends WordPressValetDriver | |
{ | |
/** | |
* Allow filename-based cache busting. | |
* @see https://gist.github.com/stidges/3d0c0317bf0d36073dd045bbcc742852 | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return bool | |
*/ | |
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 . $matches[1] . '.' . $matches[2]; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment