Skip to content

Commit bf013ba

Browse files
feat(poster): add support for marking player as maincontent (#9173)
1 parent adc132a commit bf013ba

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
@@ -28,6 +28,10 @@ class PosterImage extends ClickableComponent {
2828
constructor(player, options) {
2929
super(player, options);
3030

31+
const { mainContent } = (options && options.playerOptions) || {};
32+
33+
this.isMainContent = mainContent;
34+
3135
this.update();
3236

3337
this.update_ = (e) => this.update(e);
@@ -139,7 +143,8 @@ class PosterImage extends ClickableComponent {
139143
},
140144
{},
141145
Dom.createEl('img', {
142-
loading: 'lazy',
146+
loading: this.isMainContent ? 'eager' : 'lazy',
147+
fetchPriority: this.isMainContent ? 'high' : 'auto',
143148
crossOrigin: this.crossOrigin()
144149
}, {
145150
alt: ''

test/unit/poster.test.js

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

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

0 commit comments

Comments
 (0)