I have a HTML 5 WebComponent with shadow DOM which displays content that has to load styles depending on the content type that is displayed in the component. The list of stylesheets is fetched from the server.
I can load the stylesheets like this:
for (const style of styles) {
const stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('href', style);
stylesheet.setAttribute('type', 'text/css');
this.root.appendChild(stylesheet);
}
However, the stylesheets sometimes also include @font-face
rules, which are not added to the component. The browser never creates requests for the fonts references in the @font-face
rules. How can I load these rules dynamically?