html - Load <link> tags async with guaranteed order -


after running google pagespeed, recommended use async or defer css content

eliminate render-blocking javascript , css in above-the-fold content

your page has 6 blocking css resources. causes delay in rendering page.

none of above-the-fold content on page rendered without waiting following resources load. try defer or asynchronously load blocking resources, or inline critical portions of resources directly in html.

so exploring async attribute on <link> tag

<link rel="stylesheet" href="{{asset "css/bootstrap.min.css"}}"> <link rel="stylesheet" href="{{asset "css/font-awesome.min.css"}}"> <link rel="stylesheet" type="text/css" href="{{asset "css/screen.css"}}"> <link rel="stylesheet" type="text/css" href="{{asset "css/highlight_styles/rainbow.css"}}"> 

now if add async attribute above <link> tags, worried css not load in order. since css order matter , order can not guaranteed async other options?

options have considered:

  • using defer attribute guarantees order, doesn't seem supported <link> tag documentation

  • to cat css way can guarantee order. wondering if there way around multiple async <link> tags, pain every time gulp/grunt.

  • i write fancy javascript this, seems overkill. (js -> css -> js reduce time saved).


some references:

according webkit order seems preserved defer not async:

both async , defer scripts begin download without pausing parser , both support optional onload handler address common need perform initialization depends on script. difference between async , defer centers around when script executed. each async script executes @ first opportunity after finished downloading , before window’s load event. means it’s possible (and likely) async scripts not executed in order in occur in page. defer scripts, on other hand, guaranteed executed in order occur in page. execution starts after parsing finished, before document’s domcontentloaded event.

css order matters: does order of css stylesheet definitions matter?

w3c documentation: <link> tag supports async , no mention of defer

after further research seems few of assumptions incorrect.

the link tag type="import" can async, not type="text/css"

the best alterantive find use library called loadcss, below example of how used:

<head>     <script src="loadcss.min.js"></script>     <script>         // load file         loadcss("styles-v6.min.css");     </script> </head> 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -