mirror of
https://github.com/discourse/discourse.git
synced 2025-04-19 21:29:05 +08:00
DEV: Add link rel preload to theme-javascripts (#19231)
* DEV: Add link rel preload to theme-javascripts
This commit is contained in:
parent
07fb7fc54d
commit
aea492df5e
@ -6,7 +6,7 @@ require 'json_schemer'
|
||||
class Theme < ActiveRecord::Base
|
||||
include GlobalPath
|
||||
|
||||
BASE_COMPILER_VERSION = 67
|
||||
BASE_COMPILER_VERSION = 68
|
||||
|
||||
attr_accessor :child_components
|
||||
|
||||
@ -394,7 +394,12 @@ class Theme < ActiveRecord::Base
|
||||
end
|
||||
caches = 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")
|
||||
end
|
||||
list_baked_fields(theme_ids, target, name).map { |f| f.value_baked || f.value }.join("\n")
|
||||
end
|
||||
|
@ -148,7 +148,14 @@ class ThemeField < ActiveRecord::Base
|
||||
javascript_cache.source_map = js_compiler.source_map
|
||||
javascript_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::Base
|
||||
javascript_cache.source_map = js_compiler.source_map
|
||||
javascript_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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user