Last active
August 29, 2015 14:12
-
-
Save willmorgan/f9b6f0125476ea3a9b04 to your computer and use it in GitHub Desktop.
git-hash.php
This file contains 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
<!-- Step 0: Ensure your server configuration is correct (see sample-apache.conf) --> | |
<!-- Step 1: Include the hash script (see git-hash.php) --> | |
<?php $hash = require_once 'git-hash.php'; ?> | |
<html> | |
<!-- Step 2: Prepend the hash to any combined assets --> | |
<link rel="stylesheet" href="assets/_combined-<?=$hash?>.css" /> | |
<script src="assets/_combined-<?=$hash?>.js" /> |
This file contains 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 | |
/** | |
* Get the first 8 characters of the git sha1 hash | |
* Useful for quick and dirty cache busting for assets | |
*/ | |
$version = exec('git rev-parse HEAD'); | |
$hash = substr($version, 0, 8); | |
return $hash; |
This file contains 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
# Redirects all assets/_combined-<HASH>.css or JS files to _combined.css or JS | |
# Example: | |
# assets/_combined-ad4efc12.css => assets/_combined.css | |
# assets/_combined-ad4efc12.js => assets/_combined.js | |
# Customise to your needs - it is likely your directory structure will be different. | |
# Note: mod_rewrite MUST be enabled | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteRule ^assets/_combined-[\@a-z0-9\.]+.(js|css)$ assets/_combined.$1 [L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment