mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 22:57:40 +08:00
sprockets upgrade
stop bundling all js files in dev, replace with turbo boosted serving of assets
This commit is contained in:
21
lib/middleware/turbo_dev.rb
Normal file
21
lib/middleware/turbo_dev.rb
Normal file
@ -0,0 +1,21 @@
|
||||
module Middleware
|
||||
# this class cheats and bypasses rails altogether if the client attme
|
||||
class TurboDev
|
||||
def initialize(app, settings={})
|
||||
@app = app
|
||||
end
|
||||
def call(env)
|
||||
# hack to bypass all middleware if serving assets, a lot faster 4.5 seconds -> 1.5 seconds
|
||||
if (etag = env['HTTP_IF_NONE_MATCH']) && env['REQUEST_PATH'] =~ /^\/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
|
Reference in New Issue
Block a user