I’ll write an update to this guide over the weekend as I learned a cool trick to simplify Async CSS. Here is the full article about it: https://www.filamentgroup.com/lab/load-css-simpler/
In short, now you can drop the polyfill and instead of preloading now you can use this:
/**
* Async load CSS.
*/
if (env('WP_ENV') === 'production') {
add_filter('style_loader_tag', function ($html, $handle, $href) {
if (is_admin()) {
return $html;
}
$dom = new \DOMDocument();
$dom->loadHTML($html);
$tag = $dom->getElementById($handle . '-css');
$tag->setAttribute('media', 'print');
$tag->setAttribute('onload', "this.media='all");
$tag->removeAttribute('type');
$tag->removeAttribute('id');
$html = $dom->saveHTML($tag);
return $html;
}, 9999, 3);
}
Though regarding FOUC, that is expected when loading CSS async but critical CSS should solve that. So first thing would be to check if critical CSS is generated at all. Later I’ll share a better way to inline critical CSS as well.