File tree Expand file tree Collapse file tree 3 files changed +54
-3
lines changed Expand file tree Collapse file tree 3 files changed +54
-3
lines changed Original file line number Diff line number Diff line change @@ -66,9 +66,11 @@ A list of the [component properties](http://vuejs.org/v2/guide/components.html#P
66
66
67
67
#### Loading
68
68
69
+ - ` preload (boolean) ` - Requires Nuxt framework. If ` true ` will add ` <link rel="preload"/> ` tags to the ` <head> ` for the image assets.
70
+
69
71
- ` autoload (boolean) ` - * Default: ` true ` .* If ` true ` , assets are loaded immediately unless ` lazyload ` .
70
72
71
- - ` lazyload (boolean) ` - Waits until the Visual enters the viewport to trigger loading. Overrides, ` autoload ` .
73
+ - ` lazyload (boolean) ` - Waits until the Visual enters the viewport to trigger loading. Overrides ` autoload ` .
72
74
73
75
- ` intersection-options (object) ` - IntersectionObserver options. Used with ` lazyload ` and ` autopause ` .
74
76
Original file line number Diff line number Diff line change @@ -7,6 +7,27 @@ export default
7
7
srcset : String
8
8
webpSrcset : String
9
9
sizes : String
10
+ preload : Boolean
11
+
12
+ # Add preload link tags
13
+ head : ->
14
+ return unless @preload and @image
15
+
16
+ # Create base link attributes
17
+ preloadTag =
18
+ rel : ' preload'
19
+ as : ' image'
20
+ href : @image
21
+
22
+ # Add srcset support
23
+ if imagesrcset = @webpSrcset || @srcset
24
+ then preloadTag = Object .assign preloadTag, {
25
+ imagesrcset
26
+ imagesizes : @sizes || ' ' # Prevent "undefined" value
27
+ }
28
+
29
+ # Add link tag
30
+ return link : [ preloadTag ]
10
31
11
32
computed :
12
33
@@ -22,4 +43,3 @@ export default
22
43
23
44
# Image has finished loading
24
45
when @imageLoaded then true
25
-
Original file line number Diff line number Diff line change @@ -624,7 +624,36 @@ Logic related rendering images
624
624
image : String ,
625
625
srcset : String ,
626
626
webpSrcset : String ,
627
- sizes : String
627
+ sizes : String ,
628
+ preload : Boolean
629
+ } ,
630
+ // Add preload link tags
631
+ head : function head ( ) {
632
+ var imagesrcset , preloadTag ;
633
+
634
+ if ( ! ( this . preload && this . image ) ) {
635
+ return ;
636
+ } // Create base link attributes
637
+
638
+
639
+ preloadTag = {
640
+ rel : 'preload' ,
641
+ as : 'image' ,
642
+ href : this . image
643
+ } ; // Add srcset support
644
+
645
+ if ( imagesrcset = this . webpSrcset || this . srcset ) {
646
+ preloadTag = Object . assign ( preloadTag , {
647
+ imagesrcset : imagesrcset ,
648
+ imagesizes : this . sizes || '' // Prevent "undefined" value
649
+
650
+ } ) ;
651
+ }
652
+
653
+ return {
654
+ // Add link tag
655
+ link : [ preloadTag ]
656
+ } ;
628
657
} ,
629
658
computed : {
630
659
// Determines whether the image should be shown via v-show
You can’t perform that action at this time.
0 commit comments