渲染阻止JavaScript& CSS - Google PageSpeed

时间:2016-09-30 23:25:22

标签: javascript css

这是我的CSS代码,但保存后我的网站搞砸了,我粘贴了什么错了吗?我还有一个JavaScript文件,该文件在Google PageSpeed结果中删除了渲染阻止JavaScript。以下代码粘贴在我的标题中。

<script>
var cb = function() {
var l = document.createElement('link'); l.rel = 'stylesheet';
l.href = '<?= site_url() ?>third_party_plugins/dist/css/style.css';
l.href = '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css';
l.href = '<?= site_url() ?>resources/css/custom.css';
var h = document.getElementsByTagName('head')[0]; h.parentNode.insertBefore(l, h);
};
var raf = requestAnimationFrame || mozRequestAnimationFrame ||
webkitRequestAnimationFrame || msRequestAnimationFrame;
if (raf) raf(cb);
else window.addEventListener('load', cb);
</script>

2 个答案:

答案 0 :(得分:0)

尝试在结束</body>代码

之前移动上面的代码

答案 1 :(得分:0)

var l = document.getElementByTag('head');
l.innerHTML = div.innerHTML + '<link href="<?= site_url() ?>third_party_plugins/dist/css/style.css" rel="stylesheet" type="text/css">'+'<link href="" rel="stylesheet" type="text/css">' + '<link href="<?= site_url() ?>third_party_plugins/dist/css/style.css" rel="stylesheet" type="text/css">';

尝试使用此代替

var l = document.createElement('link'); l.rel = 'stylesheet';
l.href = '<?= site_url() ?>third_party_plugins/dist/css/style.css';
l.href = '//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css';
l.href = '<?= site_url() ?>resources/css/custom.css';
var h = document.getElementsByTagName('head')[0]; h.parentNode.insertBefore(l, h);
};