Skip to content

Commit

Permalink
Use defer for non-critical scripts (#11096)
Browse files Browse the repository at this point in the history
changelog: User-Facing Improvements, Performance, Use defer for non-critical scripts
  • Loading branch information
aduth authored Aug 16, 2024
1 parent 9ffd3a3 commit 3674e15
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
<!-- <%= t('notices.dap_participation') %> -->
<%= javascript_packs_tag_once(
'https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=GSA&subagency=TTS',
async: true,
defer: true,
id: '_fed_an_ua_tag',
preload_links_header: false,
) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{ type: 'application/json', data: { config: '' } },
false,
) %>
<%= javascript_packs_tag_once('track-errors', async: true, preload_links_header: false) if BrowserSupport.supported?(request.user_agent) %>
<%= javascript_packs_tag_once('track-errors', defer: true, preload_links_header: false) if BrowserSupport.supported?(request.user_agent) %>
<%= render_javascript_pack_once_tags %>
<% end %>

Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/script_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

context 'with attributes' do
before do
javascript_packs_tag_once('track-errors', async: true)
javascript_packs_tag_once('track-errors', defer: true)
allow(Rails.application.config.asset_sources).to receive(:get_sources).
with('track-errors').and_return(['/track-errors.js'])
allow(Rails.application.config.asset_sources).to receive(:get_assets).
Expand All @@ -121,7 +121,7 @@
output = render_javascript_pack_once_tags

expect(output).to have_css(
"script[src^='/track-errors.js'][async]",
"script[src^='/track-errors.js'][defer]",
count: 1,
visible: :all,
)
Expand Down
4 changes: 2 additions & 2 deletions spec/views/devise/sessions/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
it 'does not render DAP analytics' do
allow(view).to receive(:javascript_packs_tag_once)
expect(view).not_to receive(:javascript_packs_tag_once).
with(a_string_matching('https://dap.digitalgov.gov/'), async: true, id: '_fed_an_ua_tag')
with(a_string_matching('https://dap.digitalgov.gov/'), defer: true, id: '_fed_an_ua_tag')

render
end
Expand All @@ -195,7 +195,7 @@
allow(view).to receive(:javascript_packs_tag_once)
expect(view).to receive(:javascript_packs_tag_once).with(
a_string_matching('https://dap.digitalgov.gov/'),
async: true,
defer: true,
preload_links_header: false,
id: '_fed_an_ua_tag',
)
Expand Down

0 comments on commit 3674e15

Please sign in to comment.