From 4e7057efb1e83667b16839d235ee46f86e7d207a Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 21 Oct 2014 15:59:16 +1100 Subject: [PATCH] Clean up content type and add Expires header when serving CDN assets --- app/controllers/static_controller.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index 32db639b059..ebed2b2db49 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -86,16 +86,21 @@ class StaticController < ApplicationController end expires_in 1.year, public: true + + response.headers["Expires"] = 1.year.from_now.httpdate response.headers["Access-Control-Allow-Origin"] = params[:origin] + begin response.headers["Last-Modified"] = File.ctime(path).httpdate + response.headers["Content-Length"] = File.size(path) rescue Errno::ENOENT raise Discourse::NotFound end opts = { disposition: nil } - opts[:type] = "application/x-javascript" if path =~ /\.js$/ + + opts[:type] = "application/javascript" if path =~ /\.js$/ # we must disable acceleration otherwise NGINX strips # access control headers