在 HTML5 脚本标签中可以通过 async=true
异步加载
<script src="index.js" type="text/javascript" async="true"></script>
CSS 资源是否有任何等效项?像这样的东西:
<link rel="stylesheet" type="text/css" async="true" href="style.css">
基本原理是让浏览器加载 css 并缓存它,以供以后的请求使用,但让其余的过程畅通无阻。 例如,启动画面。
最佳答案
2021 年编辑: 原始链接已移动 - 没有 JavaScript 的异步 CSS https://codepen.io/tigt/post/async-css-without-javascript
"It seems this trick causes Chrome & Firefox to start the body earlier, and they simply don't block for body stylesheets."
<head>
<!--[if IE]>
<link rel="stylesheet" href="style.css">
<![endif]-->
</head>
<body>
<!--[if !IE]> -->
<link rel="stylesheet" href="style.css" lazyload>
<!-- <![endif]-->
</body>
文章还包含基准:
关于javascript - async=true 用于 css 链接标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24020254/