mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 21:25:24 +08:00
DEV: Simplify ember-cli proxy strategy (#24242)
Previously, the app HTML served by the Ember-CLI proxy was generated based on a 'bootstrap json' payload generated by Rails. This inevitably leads to differences between the Rails HTML and the Ember-CLI HTML. This commit overhauls our proxying strategy. Now, we totally ignore the ember-cli `index.html` file. Instead, we take the full HTML from Rails and surgically replace script URLs based on a `data-discourse-entrypoint` attribute. This should be faster (only one request to Rails), more robust, and less confusing for developers.
This commit is contained in:
@ -142,22 +142,24 @@ module ApplicationHelper
|
||||
scripts
|
||||
.map do |name|
|
||||
path = script_asset_path(name)
|
||||
preload_script_url(path)
|
||||
preload_script_url(path, entrypoint: script)
|
||||
end
|
||||
.join("\n")
|
||||
.html_safe
|
||||
end
|
||||
|
||||
def preload_script_url(url)
|
||||
def preload_script_url(url, entrypoint: nil)
|
||||
entrypoint_attribute = entrypoint ? "data-discourse-entrypoint=\"#{entrypoint}\"" : ""
|
||||
|
||||
add_resource_preload_list(url, "script")
|
||||
if GlobalSetting.preload_link_header
|
||||
<<~HTML.html_safe
|
||||
<script defer src="#{url}"></script>
|
||||
<script defer src="#{url}" #{entrypoint_attribute}></script>
|
||||
HTML
|
||||
else
|
||||
<<~HTML.html_safe
|
||||
<link rel="preload" href="#{url}" as="script">
|
||||
<script defer src="#{url}"></script>
|
||||
<link rel="preload" href="#{url}" as="script" #{entrypoint_attribute}>
|
||||
<script defer src="#{url}" #{entrypoint_attribute}></script>
|
||||
HTML
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user