]> cat aescling's git repositories - mastodon.git/commitdiff
Add dns-prefetch if using different host for assets or uploads (#8942)
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 9 Oct 2018 23:31:10 +0000 (01:31 +0200)
committerGitHub <noreply@github.com>
Tue, 9 Oct 2018 23:31:10 +0000 (01:31 +0200)
app/helpers/application_helper.rb
app/views/layouts/application.html.haml

index f8e2c0e1125b044080247256ab172e76a736ed14..8533b398a4fe3f0049c7730a50a7fa5b08b249a6 100644 (file)
@@ -81,4 +81,20 @@ module ApplicationHelper
     output << 'rtl' if locale_direction == 'rtl'
     output.reject(&:blank?).join(' ')
   end
+
+  def cdn_host
+    ENV['CDN_HOST'].presence
+  end
+
+  def cdn_host?
+    cdn_host.present?
+  end
+
+  def storage_host
+    ENV['S3_ALIAS_HOST'].presence || ENV['S3_CLOUDFRONT_HOST'].presence
+  end
+
+  def storage_host?
+    storage_host.present?
+  end
 end
index 436864237641437ea81f1c770c244fa1dcb91204..3d63dc0f350e58a7024c1c308efbcee7a7e93a04 100755 (executable)
@@ -3,6 +3,13 @@
   %head
     %meta{ charset: 'utf-8' }/
     %meta{ name: 'viewport', content: 'width=device-width, initial-scale=1' }/
+
+    - if cdn_host?
+      %link{ rel: 'dns-prefetch', href: cdn_host }/
+
+    - if storage_host?
+      %link{ rel: 'dns-prefetch', href: storage_host }/
+
     %link{ rel: 'icon', href: favicon_path, type: 'image/x-icon' }/
     %link{ rel: 'apple-touch-icon', sizes: '180x180', href: '/apple-touch-icon.png' }/
     %link{ rel: 'mask-icon', href: '/mask-icon.svg', color: '#2B90D9' }/