diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 6649e47d7c544..d976f9b5ce1c9 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -87,10 +87,15 @@ def javascript_include_tag(*sources) options = sources.extract_options!.stringify_keys path_options = options.extract!("protocol", "extname", "host", "skip_pipeline").symbolize_keys preload_links = [] + nopush = options["nopush"].nil? ? true : options.delete("nopush") sources_tags = sources.uniq.map { |source| href = path_to_javascript(source, path_options) - preload_links << "<#{href}>; rel=preload; as=script; nopush" unless options["defer"] + unless options["defer"] + preload_link = "<#{href}>; rel=preload; as=script" + preload_link += "; nopush" if nopush + preload_links << preload_link + end tag_options = { "src" => href }.merge!(options) @@ -137,10 +142,13 @@ def stylesheet_link_tag(*sources) options = sources.extract_options!.stringify_keys path_options = options.extract!("protocol", "host", "skip_pipeline").symbolize_keys preload_links = [] + nopush = options["nopush"].nil? ? true : options.delete("nopush") sources_tags = sources.uniq.map { |source| href = path_to_stylesheet(source, path_options) - preload_links << "<#{href}>; rel=preload; as=style; nopush" + preload_link = "<#{href}>; rel=preload; as=style" + preload_link += "; nopush" if nopush + preload_links << preload_link 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 317fda4fda96c..a2fc33cba83eb 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -522,6 +522,13 @@ def test_should_not_preload_links_with_defer assert_equal "", @response.headers["Link"] end + def test_should_allow_caller_to_remove_nopush + stylesheet_link_tag("http://example.com/style.css", nopush: false) + javascript_include_tag("http://example.com/all.js", nopush: false) + expected = "; rel=preload; as=style,; rel=preload; as=script" + assert_equal expected, @response.headers["Link"] + end + def test_image_path ImagePathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end