Skip to content

Instantly share code, notes, and snippets.

@jqr
Created March 26, 2009 19:52
Show Gist options
  • Save jqr/86281 to your computer and use it in GitHub Desktop.
Save jqr/86281 to your computer and use it in GitHub Desktop.
Nginx cache busting rewriter
# Nginx cache busting rewriter, best used on assets that have long-lived expires.
#
# Rewrites like so:
# blah.com/release_ab2ea212312.../file.css => blah.com/file.css
#
location ~ ^/release_(.*?)/ {
rewrite ^/release_(.*?)/(.*)$ /$2 last;
}
# A paperclip initializer, place in config/initializers/
Paperclip::Attachment.interpolations[:release_path] =
lambda do |attachment, style|
unless AssetVersion.version.blank?
"/release_#{AssetVersion.version}"
end
end
class SomeModel < ActiveRecord::Base
has_attached_file :image, {
:styles => {
:thumb => "100x100",
},
:url => ":release_path/attachments/:class/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/attachments/:class/:attachment/:id/:style/:basename.:extension",
:default_url => "/images/:class/:attachment/missing_:style.png",
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment