-
-
Save grim-reapper/1573f54312a1dc24684989cde5736895 to your computer and use it in GitHub Desktop.
Add filename-based cache busting to Laravel
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
| <IfModule mod_rewrite.c> | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteRule ^(.+)\.(\d+)\.(css|gif|jpeg|jpg|js|png|svg)$ $1.$3 [L] | |
| </IfModule> |
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 | |
| // Add the the following code right before the last line of the existing | |
| // Laravel "server.php" file, which will look something like this: | |
| // `require_once $paths['public'].'/index.php';` | |
| if (preg_match('/^(.+)\.(\d+)\.(css|gif|jpeg|jpg|js|png|svg)$/', $uri, $matches)) | |
| { | |
| $requested = $paths['public'].$matches[1].'.'.$matches[3]; | |
| if (file_exists($requested)) | |
| { | |
| $types = array( | |
| 'css' => 'text/css', | |
| 'gif' => 'image/gif', | |
| 'jpeg' => 'image/jpeg', | |
| 'jpg' => 'image/jpeg', | |
| 'js' => 'application/javascript', | |
| 'png' => 'image/png', | |
| 'svg' => 'image/svg+xml' | |
| ); | |
| header('Content-type: '.$types[$matches[3]]); | |
| readfile($requested); | |
| exit; | |
| } | |
| } |
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
| <!-- Stylesheet --> | |
| <link rel="stylesheet" href="/css/main.{{ filemtime(public_path() . '/css/main.css') }}.css"> | |
| <!-- JavaScript --> | |
| <script src="/js/min/site-ck.{{ filemtime(public_path() . '/js/min/site-ck.js') }}.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment