Skip to content

Instantly share code, notes, and snippets.

@thermistor
Created September 7, 2013 01:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thermistor/6472077 to your computer and use it in GitHub Desktop.
Save thermistor/6472077 to your computer and use it in GitHub Desktop.
turbodev!
# Extracted from http://git.io/HeGfdA
# Full credit to https://github.com/SamSaffron
#
# Middleware that causes static asset requests to bypass rails altogether. This
# can make requests a lot faster. From 4.5s to 1.5s in some apps. Only relevant
# in development environments as production already does this.
#
# Put this file in lib/middleware and add the following code to your
# development.rb environment file:
#
# config.middleware.insert 0, Middleware::TurboDev
#
# This will add the middleware to the top of the Rails middleware stack.
module MedeoMiddleware
class TurboDev
def initialize(app, settings = {})
@app = app
end
def call(env)
if (etag = env['HTTP_IF_NONE_MATCH']) && env['REQUEST_PATH'] =~ %r[^/assets/]
name = $'
etag = etag.gsub '"', ''
asset = Rails.application.assets.find_asset(name)
if asset && asset.digest == etag
return [304, {}, []]
end
end
@app.call(env)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment