Answer the question
In order to leave comments, you need to log in
Is this the right approach to include css?
Hello, tell me please. I am optimizing a website. I extracted the critical css using the tool critical
, as a result, I embed the critical css into the tag <style>...</style>
on the page.
And not critical, I connect via link:
<link href="home.css" media="print" onload="this.media='all'; this.onload=null;" rel="stylesheet">
<style>...</style>
, although this may not be a strong problem, in general, to be honest, I'm already a little confused about how best and what will be more efficient. Answer the question
In order to leave comments, you need to log in
In general, this option is more correct:
<link type="text/css" rel="preload" as="style" href="home.css" onload="this.rel='stylesheet'"/>
<script>
// Firefox не грузит стили с preload автоматически,
// поэтому в конец HTML-кода нужно добавить такое (один раз):
if (navigator.userAgent.indexOf("Firefox")>=0){
var elms = document.querySelectorAll('link[rel=preload][as=style]');
for (i=0; i<elms.length; i++){
elms[i].rel="stylesheet";}}
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question