'use strict'; // This adds event listeners to elements with `data-loadcss`, // switching them to media = "all" when they finish loading // See https://github.com/filamentgroup/loadCSS/issues/312#issuecomment-600022209 const fontCSSLinks = [...document.querySelectorAll('[data-loadcss]')]; // use the CSS on the link's `load` event fontCSSLinks.map((e) => e.addEventListener('load', (loadEvent) => { if (loadEvent.target.media !== 'all') { loadEvent.target.media = 'all'; } performance.mark('font css loaded'); }) ); // or use the CSS on Document load window.addEventListener('DOMContentLoaded', () => { fontCSSLinks.forEach((link) => { if (link.media !== 'all') { link.media = 'all'; } link.media = 'all'; performance.mark('font css enabled at document load'); }); });