From 5dd752877e0a23c258d9df018ba10d9c6eda97c3 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 17 Apr 2017 11:52:43 -0400 Subject: [PATCH] FEATURE: try adding some preload hints for chrome --- app/helpers/application_helper.rb | 12 ++++++------ .../common/_discourse_javascript.html.erb | 2 +- app/views/common/_special_font_face.html.erb | 1 + app/views/layouts/application.html.erb | 18 +++++++++--------- app/views/layouts/embed.html.erb | 2 +- app/views/layouts/finish_installation.html.erb | 4 ++-- lib/stylesheet/manager.rb | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 67651cc0a55..e534aa50da7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -45,17 +45,17 @@ module ApplicationHelper end end - def script(*args) + def preload_script(script) + path = asset_path("#{script}.js") + if GlobalSetting.cdn_url && GlobalSetting.cdn_url.start_with?("https") && ENV["COMPRESS_BROTLI"] == "1" && request.env["HTTP_ACCEPT_ENCODING"] =~ /br/ - tags = javascript_include_tag(*args) - tags.gsub!("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") - tags.html_safe - else - javascript_include_tag(*args) + path.gsub!("#{GlobalSetting.cdn_url}/assets/", "#{GlobalSetting.cdn_url}/brotli_asset/") end +" +".html_safe end def discourse_csrf_tags diff --git a/app/views/common/_discourse_javascript.html.erb b/app/views/common/_discourse_javascript.html.erb index 9e2da0a9005..05e0a95f948 100644 --- a/app/views/common/_discourse_javascript.html.erb +++ b/app/views/common/_discourse_javascript.html.erb @@ -65,4 +65,4 @@ })(); -<%= script 'browser-update' %> +<%= preload_script 'browser-update' %> diff --git a/app/views/common/_special_font_face.html.erb b/app/views/common/_special_font_face.html.erb index 8e95e5ece86..2462461c24e 100644 --- a/app/views/common/_special_font_face.html.erb +++ b/app/views/common/_special_font_face.html.erb @@ -10,6 +10,7 @@ <% font_domain = "#{request.protocol}#{request.host_with_port}&2" %> +" as="font" type="font/woff2" crossorigin />