mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Use no-cache
in development mode for assets. Using must-revalidate
, which is
Rails' default, seems to have Chrome sometimes not request assets in development mode even though it's supposed to revalidate every time.
This commit is contained in:
parent
78c15d5810
commit
858e51c8ab
1 changed files with 7 additions and 2 deletions
|
@ -6,8 +6,11 @@ module Middleware
|
||||||
@app = app
|
@app = app
|
||||||
end
|
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
|
# 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\//
|
if (etag = env['HTTP_IF_NONE_MATCH']) && is_asset
|
||||||
name = $'
|
name = $'
|
||||||
etag = etag.gsub "\"", ""
|
etag = etag.gsub "\"", ""
|
||||||
asset = Rails.application.assets.find_asset(name)
|
asset = Rails.application.assets.find_asset(name)
|
||||||
|
@ -16,7 +19,9 @@ module Middleware
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
status, headers, response = @app.call(env)
|
||||||
|
headers['Cache-Control'] = 'no-cache' if is_asset
|
||||||
|
[status, headers, response]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue