Skip to content

Commit 27a6f72

Browse files
chore: move dspublisher-header stylesheets to head (#4657) (#4658)
Co-authored-by: Tomi Virkki <[email protected]>
1 parent e52787b commit 27a6f72

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

dspublisher/theme/init-browser.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,39 @@ if (!localStorage.getItem('vaadin.docsApp.preferredExample')) {
2020
localStorage.setItem('vaadin.docsApp.preferredExample', 'Java');
2121
}
2222

23+
// Add stylesheet links to document head once
24+
if (process.env.NODE_ENV !== 'development') {
25+
const stylesheets = [
26+
{
27+
rel: 'stylesheet',
28+
href: 'https://cdn.vaadin.com/website/antlers/v2/assets/fonts/nbinternationalpro/stylesheet.css',
29+
},
30+
{
31+
rel: 'preload',
32+
as: 'style',
33+
href: 'https://cdn.vaadin.com/website/antlers/v2/assets/icons/css/line-awesome.min.css',
34+
},
35+
{
36+
rel: 'preload',
37+
as: 'style',
38+
href: 'https://cdn.vaadin.com/website/hubspot-theme/v2/haas/css/haas.css',
39+
},
40+
];
41+
42+
stylesheets.forEach(({ rel, href, as }) => {
43+
// Check if link already exists to prevent duplicates
44+
if (!document.head.querySelector(`link[href="${href}"]`)) {
45+
const link = document.createElement('link');
46+
link.rel = rel;
47+
link.href = href;
48+
if (as) {
49+
link.setAttribute('as', as);
50+
}
51+
document.head.appendChild(link);
52+
}
53+
});
54+
}
55+
2356
class Header extends LitElement {
2457
createRenderRoot() {
2558
return this;
@@ -43,21 +76,6 @@ class Header extends LitElement {
4376
}
4477

4578
return html`
46-
<link
47-
rel="stylesheet"
48-
href="https://cdn.vaadin.com/website/antlers/v2/assets/fonts/nbinternationalpro/stylesheet.css"
49-
/>
50-
<link
51-
rel="preload"
52-
as="style"
53-
href="https://cdn.vaadin.com/website/antlers/v2/assets/icons/css/line-awesome.min.css"
54-
/>
55-
<link
56-
rel="preload"
57-
as="style"
58-
href="https://cdn.vaadin.com/website/hubspot-theme/v2/haas/css/haas.css"
59-
/>
60-
6179
<div id="haas-container"></div>
6280
${this.haasImportScript()}
6381
`;

0 commit comments

Comments
 (0)