[英]Eliminate render-blocking JavaScript and CSS
I am having a trouble with figuring out what "this spsefic outcome" in Google PageSpeed Test actually mean. 我在弄清楚Google PageSpeed Test中的“这个spsefic结果”实际意味着什么时遇到了麻烦。
I am testing this website: www.loaistudio.com - https://developers.google.com/speed/pagespeed/insights/?url=www.loaistudio.com 我正在测试这个网站:www.loaistudio.com - https://developers.google.com/speed/pagespeed/insights/?url=www.loaistudio.com
Can anyone advice me please? 有人可以建议我吗? I have managed to fix all of the other errors - but I am completely stuck at this one, I understand that CSS has to be in the head of the page, is this telling not to place it in the head but at the end of the page?!
我已经设法修复了所有其他错误 - 但我完全陷入了这个错误,我明白CSS必须在页面的头部,这是告诉不要把它放在头部但是在结束时页?!
Quick answer: you just have to put your JavaScript src below your content. 快速回答:您只需将JavaScript src放在内容之下即可。
Why? 为什么? Because when your browser begins loading JavaScript, it freezes the rest until it's done with that.
因为当您的浏览器开始加载JavaScript时,它会冻结其余部分直到它完成。
Loading the content of your page first allows it to be displayed, and then JavaScript has all the time it needs to load. 首先加载页面内容可以显示它,然后JavaScript会一直加载它。
So do like this: 所以这样做:
<html>
<head>
</head>
<body>
My great body content!
<script type="text/javascript" src="my/js/files.js">
<script type="text/javascript" src="http://www.googleapi.com/my/external/scripts.js">
</body>
</html>
Instead of this (which is unfortunately still really common): 而不是这(不幸的是仍然很常见):
<html>
<head>
<script type="text/javascript" src="my/js/files.js">
<script type="text/javascript" src="http://www.googleapi.com/my/external/scripts.js">
</head>
<body>
My great body content!
</body>
</html>
或者,只需在脚本标记的末尾添加异步。
<script src='' async></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.