简体   繁体   English

解决首批内容中的JavaScript和CSS的选项

[英]Options to solve JavaScript and CSS in above-the-fold content

I validate a site using Google's Page Speed and I get the following error: 我使用Google的Page Speed验证了网站,并收到以下错误消息:

Eliminate render-blocking JavaScript and CSS in above-the-fold content

Your page has 1 blocking script resources and 1 blocking CSS resources. This causes a delay in rendering your page.

JAVASCRIPT JAVASCRIPT

I have two javascript files on bottom of my page: 我在页面底部有两个JavaScript文件:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="/scripts/main?v=5jyyqQNx45M0Mbw-ZD6J9SVac8LfWyZZLh_wq6HtfQI1" type="text/javascript" async></script>

I am getting JQuery from Google CDN and Main.js from local server. 我从Google CDN获得JQuery,从本地服务器获得Main.js。

I applied async to Main.js but this does not solve it ... 我对Main.js应用了异步,但这并不能解决问题...

... The only thing that solves this is adding async also to JQuery from Google's CDN. ...解决此问题的唯一方法就是从Google的CDN向JQuery添加异步。

But then the code in Main.js using JQuery stops working ... No idea why. 但是然后Main.js中使用JQuery的代码停止工作了……不知道为什么。

CSS CSS

I am not sure what to do to solve it. 我不确定该怎么做。 Any suggestion? 有什么建议吗?

Could someone, please, help me out? 有人可以帮帮我吗?

Thank You, Miguel 谢谢米格尔

But then the code in Main.js using JQuery stops working ... No idea why. 但是然后Main.js中使用JQuery的代码停止工作了……不知道为什么。

That code breaks, because jQuery is loaded after Main.js is executed and as Main.js depends on it .. well, it's going to fail. 该代码中断了,因为jQuery是在Main.js执行后加载的,并且因为Main.js依赖于它..很好,它将失败。

You won't come around loading your CSS and JS, therefore there isn't really anything you could do - Except using pure HTML. 您将不会加载CSS和JS,因此实际上您无能为力-除了使用纯HTML外。

The linked google help page says: 链接的Google帮助页面显示

  • If your CSS/JS file is quite small, then load it using inline tags 如果您的CSS / JS文件很小,请使用内联标签加载
  • You can try to put important CSS/JS in one file and not-so-important one in another file which is loaded async 您可以尝试将重要的CSS / JS放在一个文件中,而将不太重要的CSS / JS放在另一个异步加载的文件中

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 nopcommerce 3.80折叠式内容中的阻止发布者的JavaScript和CSS - nopcommerce 3.80 ender-blocking JavaScript and CSS in above-the-fold content 在不影响响应性和性能的情况下,消除即时内容解决方案中阻止渲染的JavaScript和CSS - Eliminate render-blocking JavaScript and CSS in above-the-fold content solution without affecting responsiveness and performance 如何“消除首屏内容中的阻止渲染的JavaScript和CSS” - How to “Eliminate render-blocking JavaScript and CSS in above-the-fold content” 如何修复 joomla 中的“在首屏内容中消除阻止渲染的 JavaScript 和 CSS” - How to fix “Eliminate render-blocking JavaScript and CSS in above-the-fold content” in joomla OpenCart PageSpeed-在首屏内容中消除渲染阻止的JavaScript和CSS - OpenCart PageSpeed - Eliminate render-blocking JavaScript and CSS in above-the-fold content 在首屏内容中消除阻止渲染的JavaScript和CSS-Wordpress - Eliminate render-blocking JavaScript and CSS in above-the-fold content - Wordpress 什么是 Google Pagespeed 中的“首屏内容”? - What is “above-the-fold content” in Google Pagespeed? Google PageSpeed消除了折叠式内容Wordpress中的渲染阻止CSS - Google PageSpeed Eliminate render-blocking CSS in above-the-fold content Wordpress “尽管所有JS都位于页面的底部,但是在首映内容中消除了渲染阻止JavaScript” - “Eliminate render-blocking JavaScript in above-the-fold content” even though all JS is at the bottom of the page? 使用CDN的Google PageSpeed Insight CSS Javascript问题 - Google PageSpeed Insight CSS Javascript “above the fold” issue using CDN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM