File size: 514 Bytes
8766bc5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | export function mount_css(url: string, target: HTMLElement): Promise<void> {
const existing_link = document.querySelector(`link[href='${url}']`);
if (existing_link) return Promise.resolve();
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = url;
return new Promise((res, rej) => {
link.addEventListener("load", () => res());
link.addEventListener("error", () => {
console.error(`Unable to preload CSS for ${url}`);
res();
});
target.appendChild(link);
});
}
|