Skip to content

Commit b30ad53

Browse files
committed
add support for marking player as maincontent
When maincontent is set to true the poster img element will get loading=eager and fetchpriority=high to decrease LCP time. closes #9171
1 parent 69ea0e0 commit b30ad53

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/js/poster-image.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class PosterImage extends ClickableComponent {
2727
constructor(player, options) {
2828
super(player, options);
2929

30+
const { maincontent } = (options && options.playerOptions) || {};
31+
32+
this.isMainContent = maincontent;
33+
3034
this.update();
3135

3236
this.update_ = (e) => this.update(e);
@@ -138,7 +142,8 @@ class PosterImage extends ClickableComponent {
138142
},
139143
{},
140144
Dom.createEl('img', {
141-
loading: 'lazy',
145+
loading: this.isMainContent ? 'eager' : 'lazy',
146+
fetchPriority: this.isMainContent ? 'high' : 'auto',
142147
crossOrigin: this.crossOrigin()
143148
}, {
144149
alt: ''

test/unit/poster.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ QUnit.test('should create and update a poster image', function(assert) {
3131
posterImage.dispose();
3232
});
3333

34+
QUnit.test('should mark img as prioritized request when maincontent is true', function(assert) {
35+
const posterImage = new PosterImage(this.mockPlayer, { playerOptions: { maincontent: true } });
36+
37+
assert.equal(posterImage.$('img').loading, 'eager', 'img is loading eager');
38+
assert.equal(posterImage.$('img').fetchPriority, 'high', 'img has fetchpriority high');
39+
40+
posterImage.dispose();
41+
});
42+
3443
QUnit.test('should mirror crossOrigin', function(assert) {
3544
assert.strictEqual(this.mockPlayer.posterImage.$('img').crossOrigin, null, 'crossOrigin not set when not present in options');
3645
assert.strictEqual(this.mockPlayer.posterImage.crossOrigin(), null, 'crossOrigin not set from getter when not present in options');

0 commit comments

Comments
 (0)