javascript - 即使在异步加载资源后,Google Page Speed 仍然会出现渲染阻塞问题

标签 javascript asynchronous pagespeed deferred-loading

Google Page Speed Insights

"Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML."

上述问题提示我需要 2 个样式表。因此,我使用以下代码加载样式表以延迟样式表的加载。

window.onload = loadResource;

function loadResource(){
    css_array=[resource1,resource2];
    css_init(css_array);
}

function css_init(hrefPath){
    for(a = 0; a < hrefPath.length; a++){
        link=document.createElement('link');
        link.href=hrefPath[a];
        link.rel='stylesheet';
        document.getElementsByTagName('head')[0].appendChild(link);
    }
}

使用上面的代码,在 DOMContentLoaded 事件Load 事件 被触发后加载所有 css 样式表(chrome 开发工具的网络选项卡)

但即使有了上述渲染阻塞问题仍未解决。知道为什么它不起作用以及如何正确延迟 css 样式表吗?感谢您的帮助!

最佳答案

关于javascript - 即使在异步加载资源后,Google Page Speed 仍然会出现渲染阻塞问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21400708/

相关文章:

javascript - 使用 jQuery 将监听器附加到 iframe 内的顶部窗口焦点事件

c# - C# .NET 中的异步 POST 请求

c# - MVC 中的异步/等待 - 为什么在长时间运行的操作期间释放线程很重要

java - 如何使用 java 的 ImageIO 保存优化的 png 图像?

pageload - 为什么 Google 建议在 noscript 中包装样式表链接?

javascript - 如何在 Rails 3.1 中将 jquery 替换为原型(prototype)

javascript - 通过对象属性识别对象数组

javascript - 没有 'Access-Control-Allow-Origin' 但仍在处理

javascript - 正确的 promise 链

java - GAE 部署页面速度警告