Created
October 31, 2013 23:48
-
-
Save tatey/7259055 to your computer and use it in GitHub Desktop.
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
class Deflater | |
def initialize app | |
@app = app | |
end | |
def call env | |
if acceptable_method?(env) && compress?(env) | |
Rack::Deflater.new(app).call env | |
else | |
app.call env | |
end | |
end | |
private | |
attr_reader :app | |
def acceptable_method? env | |
['GET', 'HEAD'].include? env['REQUEST_METHOD'] | |
end | |
def compress? env | |
env['REQUEST_PATH'] !~ /\.(png|jpg|jpeg|gif)\z/ | |
end | |
end |
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
# Sets the correct headers when serving files from /public. CloudFront | |
# will forward these headers to the client. | |
config.middleware.insert 0, 'Rack::Static', | |
urls: Rails.root.join('public').children(false).map { |p| "/#{p}" }, | |
root: Rails.root.join('public'), | |
header_rules: [ | |
# Clients should cache assets for one year. | |
['/assets', {'Cache-Control' => 'public, max-age=3136000'}], | |
# Provide web fonts with cross-origin access-control-headers | |
# Firefox requires this when serving assets using a CDN. | |
[:fonts, {'Access-Control-Allow-Origin' => '*'}] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment