Skip to content

Instantly share code, notes, and snippets.

@dctabuyz
Last active February 22, 2017 16:28
Show Gist options
  • Save dctabuyz/bb6ba3da06c3a305c3354b6e6169e92f to your computer and use it in GitHub Desktop.
Save dctabuyz/bb6ba3da06c3a305c3354b6e6169e92f to your computer and use it in GitHub Desktop.
bust static cache on git checkout: insert git revision id (HEAD) into a link
  • add filter
$ git config filter.nocache.smudge "perl -pe 'BEGIN {\$h = \`git log --pretty=format:\"%H\" -1\`; } s{\\?[A-z0-9]*#cache-bust}{?\$h#cache-bust}g'"
$ git config filter.nocache.clean "perl -pe 's{\\?[A-z0-9]*#cache-bust}{?nocache#cache-bust}g'"
  • edit .gitattributes
*.html filter=nocache

and this <link media="all" href="/css/main.css?nocache#cache-bust" type="text/css" rel="stylesheet">

on checkout will be transformed into something like this <link media="all" href="/css/main.css?a761f5f48b8d7389069982d82a6c945fddd687a9#cache-bust" type="text/css" rel="stylesheet">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment