PageSpeed指责“渲染阻塞”脚本当使用外部图像时 [英] PageSpeed accuses script of "render-blocking" when using external image

查看:116
本文介绍了PageSpeed指责“渲染阻塞”脚本当使用外部图像时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面正文的结束标记之前放置了CDN中的脚本(位于< / body> 之上)。 Google的PageSpeed Insights表示:


消除以上折叠内容中的呈现屏蔽JavaScript和CSS

您的页面有1个阻止脚本资源。


在我的< / body> ; 不要延迟渲染?



经过一些试验和错误后,我发现这是由于我的页面使用外部图像。通过下面的例子,您可以使PageSpeed检测到渲染阻止脚本:

 < body> 
< img src =http://i.stack.imgur.com/oURrw.png/>
< script src =https://code.jquery.com/jquery-3.1.1.min.js>< / script>
< / body>

这是否真的会延迟渲染我的页面?

< / body> don'结尾之前,我想到了脚本: t延迟渲染?


正确,他们没有。


例如,对于我来说,这个(带图片)会触发 https://code.jquery.com/jquery-3.1.1.min的呈现阻止警告。 js



...



如果我删除 img ,渲染阻塞JavaScript警告消失。


我会报告错误。我没有看到任何关于该脚本的渲染阻塞。我甚至尝试在固定大小的 overflow:none div 中包装 img code>,仍然有错误。看不到为什么该脚本会呈现阻塞状态;如果你将它报告为一个错误,结果是有原因的,那么这是一个好结果。但更可能是一个错误。


I have placed a script from a CDN just before the closing tag of my page's body (above </body>). Google's PageSpeed Insights says:

Eliminate render-blocking JavaScript and CSS in above-the-fold content
Your page has 1 blocking script resources. This causes a delay in rendering your page.

I thought scripts before the end of my </body> don't delay the rendering?

After some trial and error I found out that this is caused because my page uses an external image. With the example below you can cause PageSpeed to detect a "render-blocking" script:

<body>
    <img src="http://i.stack.imgur.com/oURrw.png" />
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</body>

Does this really cause a delay in rendering my page?

解决方案

I thought scripts before the end of my </body> don't delay the rendering?

Correct, they don't.

For instance, for me, this (with the image) triggers the render-blocking warning for https://code.jquery.com/jquery-3.1.1.min.js:

...

If I remove the img, the render-blocking-JavaScript warning disappears.

I'd report that as a bug. I don't see anything render-blocking about that script. I even tried wrapping the img in a fixed-size, overflow: none div, and still got the error. Can't see why that script would be render-blocking; if you report it as a bug, and it turns out there's a reason, well, that's a good result. But more likely it's a bug.

这篇关于PageSpeed指责“渲染阻塞”脚本当使用外部图像时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆