A platform for community discussion. Free, open, simple.
DEV: Add link rel preload to theme-javascripts (#19231)
Isaac Janzenaea492df5e76
diff --git a/app/models/theme.rb b/app/models/theme.rbindex c8b577763f0..ef34ef6a946 100644--- a/app/models/theme.rb+++ b/app/models/theme.rb@@ -6,7 +6,7 @@ require 'json_schemer'class Theme < ActiveRecord::Baseinclude GlobalPath- BASE_COMPILER_VERSION = 67+ BASE_COMPILER_VERSION = 68attr_accessor :child_components@@ -394,7 +394,12 @@ class Theme < ActiveRecord::Baseendcaches = JavascriptCache.where(theme_id: theme_ids)caches = caches.sort_by { |cache| theme_ids.index(cache.theme_id) }- return caches.map { |c| "<script defer src='#{c.url}' data-theme-id='#{c.theme_id}'></script>" }.join("\n")+ return caches.map do |c|+ <<~HTML.html_safe+ <link rel="preload" href="#{c.url}" as="script">+ <script defer src='#{c.url}' data-theme-id='#{c.theme_id}'></script>+ HTML+ end.join("\n")endlist_baked_fields(theme_ids, target, name).map { |f| f.value_baked || f.value }.join("\n")enddiff --git a/app/models/theme_field.rb b/app/models/theme_field.rbindex 475e3541565..4c45b08b60d 100644--- a/app/models/theme_field.rb+++ b/app/models/theme_field.rb@@ -148,7 +148,14 @@ class ThemeField < ActiveRecord::Basejavascript_cache.source_map = js_compiler.source_mapjavascript_cache.save!- doc.add_child("<script defer src='#{javascript_cache.url}' data-theme-id='#{theme_id}'></script>") if javascript_cache.content.present?+ if javascript_cache.content.present?+ doc.add_child(+ <<~HTML.html_safe+ <link rel="preload" href="#{javascript_cache.url}" as="script">+ <script defer src='#{javascript_cache.url}' data-theme-id='#{theme_id}'></script>+ HTML+ )+ end[doc.to_s, errors&.join("\n")]end@@ -241,7 +248,13 @@ class ThemeField < ActiveRecord::Basejavascript_cache.source_map = js_compiler.source_mapjavascript_cache.save!doc = ""- doc = "<script defer src='#{javascript_cache.url}' data-theme-id='#{theme_id}'></script>" if javascript_cache.content.present?+ if javascript_cache.content.present?+ doc =+ <<~HTML.html_safe+ <link rel="preload" href="#{javascript_cache.url}" as="script">+ <script defer src='#{javascript_cache.url}' data-theme-id='#{theme_id}'></script>+ HTML+ end[doc, errors&.join("\n")]end