DEV: Consolidate experimental 'Link' header implementations (#26377)

This commit removes the 'experimental_preconnect_link_header' site setting, and the 'preload_link_header' site setting, and introduces two new global settings: early_hint_header_mode and early_hint_header_name.

We don't actually send 103 Early Hint responses from Discourse. However, upstream proxies can be configured to cache a response header from the app and use that to send an Early Hint response to future clients.

- `early_hint_header_mode` specifies the mode for the early hint header. Can be nil (disabled), "preconnect" (lists just CDN domains) or "preload" (lists all assets).
- `early_hint_header_name` specifies which header name to use for the early hint. Defaults to "Link", but can be changed to support different proxy mechanisms.
This commit is contained in:
David Taylor
2024-03-27 09:06:50 +00:00
committed by GitHub
parent 23fc0fb078
commit 1cc8c72a98
7 changed files with 68 additions and 79 deletions

View File

@ -133,42 +133,42 @@ RSpec.describe ApplicationHelper do
describe "add_resource_preload_list" do
it "adds resources to the preload list when it's available" do
@links_to_preload = []
@asset_preload_links = []
add_resource_preload_list("/assets/start-discourse.js", "script")
add_resource_preload_list("/assets/discourse.css", "style")
expect(@links_to_preload.size).to eq(2)
expect(@asset_preload_links.size).to eq(2)
end
it "doesn't add resources to the preload list when it's not available" do
@links_to_preload = nil
@asset_preload_links = nil
add_resource_preload_list("/assets/start-discourse.js", "script")
add_resource_preload_list("/assets/discourse.css", "style")
expect(@links_to_preload).to eq(nil)
expect(@asset_preload_links).to eq(nil)
end
it "adds resources to the preload list when preload_script is called" do
@links_to_preload = []
@asset_preload_links = []
helper.preload_script("start-discourse")
expect(@links_to_preload.size).to eq(1)
expect(@asset_preload_links.size).to eq(1)
end
it "adds resources to the preload list when discourse_stylesheet_link_tag is called" do
@links_to_preload = []
@asset_preload_links = []
helper.discourse_stylesheet_link_tag(:desktop)
expect(@links_to_preload.size).to eq(1)
expect(@asset_preload_links.size).to eq(1)
end
it "adds resources as the correct type" do
@links_to_preload = []
@asset_preload_links = []
helper.discourse_stylesheet_link_tag(:desktop)
helper.preload_script("start-discourse")
expect(@links_to_preload[0]).to match(/as="style"/)
expect(@links_to_preload[1]).to match(/as="script"/)
expect(@asset_preload_links[0]).to match(/as="style"/)
expect(@asset_preload_links[1]).to match(/as="script"/)
end
end