DEV: Defer loading core/plugin/theme JS files (#17063)

This is pre-request work to introduce a splash screen while site assets load.

The only change this commit introduces is that it ensures we add the defer attribute to core/plugin/theme .JS files. This will allow us to insert markup before the browser starts evaluating those scripts later on. It has no visual or functional impact on core.

This will not have any impact on how themes and plugins work. The only exception is themes loading external scripts in the </head> theme field directly via script tags. Everything will work the same but those would need to add the defer attribute if they want to keep the benefits introduced in this PR.
This commit is contained in:
Joe
2022-06-20 09:47:37 +08:00
committed by GitHub
parent 410ab5d587
commit 804b8fd9f9
11 changed files with 30 additions and 24 deletions

View File

@@ -154,7 +154,7 @@ class Theme < ActiveRecord::Base
SvgSprite.expire_cache
end
BASE_COMPILER_VERSION = 55
BASE_COMPILER_VERSION = 56
def self.compiler_version
get_set_cache "compiler_version" do
dependencies = [
@@ -391,7 +391,7 @@ 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 src='#{c.url}' data-theme-id='#{c.theme_id}'></script>" }.join("\n")
return caches.map { |c| "<script defer src='#{c.url}' data-theme-id='#{c.theme_id}'></script>" }.join("\n")
end
list_baked_fields(theme_ids, target, name).map { |f| f.value_baked || f.value }.join("\n")
end