diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index cbf64867aafb75a24477b4f43dbf777a12e80b67..6649e47d7c5445581e916c4cf91d60ffbab06f89 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -90,7 +90,7 @@ def javascript_include_tag(*sources) sources_tags = sources.uniq.map { |source| href = path_to_javascript(source, path_options) - preload_links << "<#{href}>; rel=preload; as=script" + preload_links << "<#{href}>; rel=preload; as=script; nopush" unless options["defer"] tag_options = { "src" => href }.merge!(options) @@ -140,7 +140,7 @@ def stylesheet_link_tag(*sources) sources_tags = sources.uniq.map { |source| href = path_to_stylesheet(source, path_options) - preload_links << "<#{href}>; rel=preload; as=style" + preload_links << "<#{href}>; rel=preload; as=style; nopush" tag_options = { "rel" => "stylesheet", "media" => "screen", diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index a59929a2eadd14a486afa12b75209ef09672c9ea..317fda4fda96c5395b6233f03fabb629fe86b7b8 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -513,10 +513,15 @@ def test_javascript_include_tag_without_request def test_should_set_preload_links stylesheet_link_tag("http://example.com/style.css") javascript_include_tag("http://example.com/all.js") - expected = "; rel=preload; as=style,; rel=preload; as=script" + expected = "; rel=preload; as=style; nopush,; rel=preload; as=script; nopush" assert_equal expected, @response.headers["Link"] end + def test_should_not_preload_links_with_defer + javascript_include_tag("http://example.com/all.js", defer: true) + assert_equal "", @response.headers["Link"] + end + def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end