method
preload_link_tag
v6.0.0 -
Show latest stable
-
0 notes -
Class: ActionView::Helpers::AssetTagHelper
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (38)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
preload_link_tag(source, options = {})
public
Returns a link tag that browsers can use to preload the source. The source can be the path of a resource managed by asset pipeline, a full path, or an URI.
Options
-
:type - Override the auto-generated mime type, defaults to the mime type for source extension.
-
:as - Override the auto-generated value for as attribute, calculated using source extension and mime type.
-
:crossorigin - Specify the crossorigin attribute, required to load cross-origin resources.
-
:nopush - Specify if the use of server push is not desired for the resource. Defaults to false.
Examples
preload_link_tag("custom_theme.css") # => <link rel="preload" href="/assets/custom_theme.css" as="style" type="text/css" /> preload_link_tag("/videos/video.webm") # => <link rel="preload" href="/videos/video.mp4" as="video" type="video/webm" /> preload_link_tag(post_path(format: :json), as: "fetch") # => <link rel="preload" href="/posts.json" as="fetch" type="application/json" /> preload_link_tag("worker.js", as: "worker") # => <link rel="preload" href="/assets/worker.js" as="worker" type="text/javascript" /> preload_link_tag("//example.com/font.woff2") # => <link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="anonymous"/> preload_link_tag("//example.com/font.woff2", crossorigin: "use-credentials") # => <link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="use-credentials" /> preload_link_tag("/media/audio.ogg", nopush: true) # => <link rel="preload" href="/media/audio.ogg" as="audio" type="audio/ogg" />