From eb90b8bc86e758045a707cae43d11dab538ca6db Mon Sep 17 00:00:00 2001 From: Guillermo Iguaran Date: Tue, 28 Nov 2017 00:58:55 -0500 Subject: Add preload_link_tag helper. This helper creates a link tag with preload keyword that allows to browser to initiate early fetch of resources. Additionally this send Early Hints if supported. See https://github.com/rails/rails/pull/30744/commits/59a02fb7bcbe68f26e1e7fdcec45c00c66e4a065 for more details about Early Hints. Preload spec: https://w3c.github.io/preload/ --- actionview/test/template/asset_tag_helper_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'actionview/test') diff --git a/actionview/test/template/asset_tag_helper_test.rb b/actionview/test/template/asset_tag_helper_test.rb index a8b66191bc..284dacf2d4 100644 --- a/actionview/test/template/asset_tag_helper_test.rb +++ b/actionview/test/template/asset_tag_helper_test.rb @@ -214,6 +214,17 @@ class AssetTagHelperTest < ActionView::TestCase %(favicon_link_tag 'mb-icon.png', :rel => 'apple-touch-icon', :type => 'image/png') => %() } + PreloadLinkToTag = { + %(preload_link_tag '/styles/custom_theme.css') => %(), + %(preload_link_tag '/videos/video.webm') => %(), + %(preload_link_tag '/posts.json', as: 'fetch') => %(), + %(preload_link_tag '/users', as: 'fetch', type: 'application/json') => %(), + %(preload_link_tag '//example.com/map?callback=initMap', as: 'fetch', type: 'application/javascript') => %(), + %(preload_link_tag '//example.com/font.woff2') => %(), + %(preload_link_tag '//example.com/font.woff2', crossorigin: 'use-credentials') => %(), + %(preload_link_tag '/media/audio.ogg', nopush: true) => %() + } + VideoPathToTag = { %(video_path("xml")) => %(/videos/xml), %(video_path("xml.ogg")) => %(/videos/xml.ogg), @@ -535,6 +546,10 @@ class AssetTagHelperTest < ActionView::TestCase FaviconLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end + def test_preload_link_tag + PreloadLinkToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } + end + def test_video_path VideoPathToTag.each { |method, tag| assert_dom_equal(tag, eval(method)) } end -- cgit v1.2.3