内联脚本_通过数据的异步内联脚本:URI

本文探讨了内联脚本如何导致样式表阻塞,影响页面加载速度。通过将内联脚本转换为指向URI的数据URL,可以实现同步到异步的转变,从而避免阻塞问题。这种方法在大部分浏览器中有效,但在Edge中可能不适用。
摘要由CSDN通过智能技术生成
内联脚本

内联脚本

Inline scripts are synchronous. "Well, duh!" you may say. That's a feature, not a bug. Because accessing a variable after an inline script should succeed. And that's fine. But not great.

内联脚本是同步的。 “好吧,du!” 你可以这样说。 这是一个功能,而不是错误。 因为在内联脚本之后访问变量应该成功。 很好。 但不是很好。

When is this bad? Well, inline scripts cause stylesheets to be blocking. Wait, what? Steve explained it 10 years ago, and it's still relevant today. Allow me to demonstrate.

什么时候不好? 好吧,内联脚本会导致样式表被阻塞。 等一下史蒂夫(Steve)于10年前进行了解释,直到今天仍然有用。 请允许我示范。

基线 (The baseline)

Say we have:

说我们有:

  • CSS1 artificially delayed to take 5 seconds to load

    人为延迟CSS1加载需要5秒
  • External async JS1 that loads fine and prints to the console

    外部异步JS1,可以正常加载并打印到控制台
  • CSS2 that takes 10 seconds to load

    加载CSS2需要10秒
  • External async JS2

    外部异步JS2
  <link rel="stylesheet" href="css1.css.php" type="text/css" />
  <script src="js1.js" async></script>
  <link rel="stylesheet" href="css2.css.php" type="text/css"/>
  <script src="js2.js" async></script>

What we have is a waterfall like this:

我们拥有的是这样的瀑布:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值