Created
July 30, 2014 16:46
-
-
Save shawndeprey/01347d1dd1dfec9b68f2 to your computer and use it in GitHub Desktop.
A Helper to Serve Gzip Assets
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
module GzipHelper | |
def gzip_javascript_include_tag(asset) | |
# Grab the asset html include tag | |
tag = javascript_include_tag asset | |
# If we are in production and the requesting client accepts gzip encoding, swap for the gzip asset | |
if Rails.env.production? && request.accept_encoding =~ /gzip/i | |
tag = tag.gsub(/\.js/i, ".js.gz") | |
end | |
# Return the asset whether or not it was modified | |
tag.html_safe | |
end | |
def gzip_stylesheet_link_tag(asset) | |
# Grab the asset html include tag | |
tag = stylesheet_link_tag asset | |
# If we are in production and the requesting client accepts gzip encoding, swap for the gzip asset | |
if Rails.env.production? && request.accept_encoding =~ /gzip/i | |
tag = tag.gsub(/\.css/i, ".css.gz") | |
end | |
# Return the asset whether or not it was modified | |
tag.html_safe | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could probably modify the methods to pass turbolinks instructions onto the javascript/stylesheet link tag methods,
e.g:
Then you can use the method in the same way you'd use a normal javascript/stylesheet tag, just include the same turboscript arguments.