From 180fd4baf2fab39baa6396455de2f7c4d045d726 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Wed, 9 May 2018 14:21:54 -0500 Subject: refactor webpack_link_tags --- app/helpers/webpack_helper.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'app/helpers/webpack_helper.rb') diff --git a/app/helpers/webpack_helper.rb b/app/helpers/webpack_helper.rb index 6ec9bce6542..d040a869dc3 100644 --- a/app/helpers/webpack_helper.rb +++ b/app/helpers/webpack_helper.rb @@ -35,10 +35,10 @@ module WebpackHelper end [ + *webpack_link_tags(preload, rel: "preload", as: "script"), + *webpack_link_tags(prefetch, rel: "prefetch"), javascript_include_tag(*chunks), - webpack_link_tag(*preload, rel: "preload", as: "script"), - webpack_link_tag(*prefetch, rel: "prefetch") - ].reject(&:empty?).join("\n").html_safe + ].join("\n").html_safe end def webpack_entrypoint_paths(source, extension: nil, exclude_duplicates: true) @@ -104,11 +104,13 @@ module WebpackHelper File.join(webpack_public_host.to_s, relative_path.to_s, webpack_path.to_s, '') end - def webpack_link_tag(*paths) - options = paths.extract_options!.stringify_keys + def webpack_link_tags(paths, options = {}) paths.uniq.map do |path| - tag_options = { "href" => path }.merge!(options) + tag_options = { + rel: "prefetch", + href: path + }.merge!(options) content_tag(:link, "", tag_options) - end.join("\n").html_safe + end end end -- cgit v1.2.1