Created
October 17, 2013 15:43
-
-
Save daneden/7027258 to your computer and use it in GitHub Desktop.
I whipped up a cache-buster for Jekyll, similar to the jekyll-assets method. Basically, when you run `jekyll build`, cachebuster.rb generates a hash based on the current time, and shoves it into the default.html template. Requests for style-{hash}.css are redirected to style.css by .htaccess
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
RewriteRule (.+)-[a-zA-Z0-9]+(\.(js|css))$ $1$2 [L] |
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
# /_plugins/cachebuster.rb | |
require 'digest/sha1' | |
module Jekyll | |
class CacheBuster < Liquid::Tag | |
def render(context) | |
"#{Digest::SHA1.hexdigest(Time.now.to_s)}" | |
end | |
end | |
end | |
Liquid::Template.register_tag('bust_cache', Jekyll::CacheBuster) |
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
<!-- /_layouts/default.html --> | |
<html lang="en"> | |
<head> | |
<!-- ... --> | |
<link rel="stylesheet" href="/assets/css/style-{% bust_cache %}.css"> | |
<!-- E.G. Outputs <link rel="stylesheet" href="/assets/css/style-afdebe725f30fd53978fabf045308bd1127b3a95.css"> --> | |
<script src="/assets/js/app-{% bust_cache %}.js"></script> | |
<!-- ... --> | |
</head> | |
<body> | |
<!-- ... --> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment