diff --git a/lib/middleware/turbo_dev.rb b/lib/middleware/turbo_dev.rb index 81f4070be..03b3c5753 100644 --- a/lib/middleware/turbo_dev.rb +++ b/lib/middleware/turbo_dev.rb @@ -1,12 +1,22 @@ module Middleware - # this class cheats and bypasses rails altogether if the client attempts - # to download a static asset + + # Cheat and bypass Rails in development mode if the client attempts to download a static asset + # that's already been downloaded. + # + # Also ensures that assets are not cached in development mode. Around Chrome 29, the behavior + # of `must-revalidate` changed and would often not request assets that had changed. + # + # To use, include in your project and add the following to development.rb: + # + # require 'middleware/turbo_dev' + # config.middleware.insert 0, Middleware::TurboDev + # class TurboDev def initialize(app, settings={}) @app = app end - def call(env) + def call(env) is_asset = (env['REQUEST_PATH'] =~ /^\/assets\//) # hack to bypass all middleware if serving assets, a lot faster 4.5 seconds -> 1.5 seconds @@ -24,4 +34,5 @@ module Middleware [status, headers, response] end end + end