Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 466a16a

Browse files
feat(#12): add a preconnect information for youtube video if used
1 parent 0832ae3 commit 466a16a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/components/extra/deckdeckgo-youtube/deckdeckgo-youtube.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,35 @@ export class DeckdeckgoYoutube {
1515
@Prop() height: number;
1616

1717
async componentDidLoad() {
18+
await this.addPreconnectLink();
19+
1820
await this.createIFrame();
1921
}
2022

23+
private addPreconnectLink(): Promise<void> {
24+
return new Promise<void>((resolve) => {
25+
if (!this.src) {
26+
resolve();
27+
return;
28+
}
29+
30+
const links: NodeListOf<HTMLElement> = document.head.querySelectorAll('link[rel=\'preconnect\']');
31+
32+
if (links && links.length > 0) {
33+
resolve();
34+
return;
35+
}
36+
37+
const link: HTMLLinkElement = document.createElement('link');
38+
link.rel = 'preconnect';
39+
link.href = 'https://www.youtube.com';
40+
41+
document.head.appendChild(link);
42+
43+
resolve();
44+
});
45+
}
46+
2147
@Method()
2248
async updateIFrame(width: number, height: number) {
2349
const iframe: HTMLIFrameElement = this.el.shadowRoot.querySelector('iframe');

0 commit comments

Comments
 (0)