From 4fbfc6ddbce7400e3ea3f6c01d949940b823c003 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 21 May 2015 16:09:23 +1000 Subject: [PATCH] PERF: missing caching on CSS and Site Customizations --- app/controllers/site_customizations_controller.rb | 7 +++++++ app/controllers/stylesheets_controller.rb | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/site_customizations_controller.rb b/app/controllers/site_customizations_controller.rb index 78f2177b3da..46af82b035b 100644 --- a/app/controllers/site_customizations_controller.rb +++ b/app/controllers/site_customizations_controller.rb @@ -2,6 +2,13 @@ class SiteCustomizationsController < ApplicationController skip_before_filter :preload_json, :check_xhr, :redirect_to_login_if_required def show + version = params["v"] + + if version && version == request.headers['If-None-Match'] + return render nothing: true, status: 304 + end + + response.headers["ETag"] = version if version expires_in 1.year, public: true render text: SiteCustomization.stylesheet_contents(params[:key], params[:target] == "mobile" ? :mobile : :desktop), content_type: "text/css" diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index 688b05ad1ca..cec57ddcba0 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -4,8 +4,12 @@ class StylesheetsController < ApplicationController def show target,digest = params[:name].split("_") - digest_orig = digest + + if digest_orig && digest_orig == request.headers['If-None-Match'] + return render nothing: true, status: 304 + end + digest = "_" + digest if digest # Security note, safe due to route constraint @@ -26,6 +30,7 @@ class StylesheetsController < ApplicationController end end + response.headers['ETag'] = digest_orig if digest_orig expires_in 1.year, public: true unless Rails.env == "development" send_file(location, disposition: :inline)