Render blocking javascripts

What is render blocking?

Render means loading, so if a javascript is render-blocking, it means that the javascript is keeping the page from loading.

Google recommends 1 to remove or defer javascripts that interfere with loading the above the fold content of your webpages.

Above the fold means what a user sees initially on their screen. That screen might be a phone, ipad, desktop or whatever the user is using to see your webpage.

This practice has long been used by people who are into pagespeed, but is new to the vast majority of webmasters and designers and can be a bit confusing, and may even seem impossible to do.

It is not only possible, it is also required to be good web citizen and even if you you don‘t care about users with slow connections, you do care about your ranking in Google. Your ranking in Google is at risk if you don‘t optimize for this. Specifically, if Google sees that your webpage does not load well for certain devices (phones, ipads, etc.) they won‘t include you in the results because Google doesn‘t want to send users to slow pages or pages that cause the user to wait too long for the content.

How to identify render-blocking javascripts

You need to know what your page is loading. There are several ways to do this. I suggest you look at what your page is loading with our request tool to get a glimpse at the scope of the issues your page faces. To get the specific files that are currently blocking rendering you should use the Google pagespeed insights tool. This tool will tell you the exact files that are blocking a particular page.

How to remove render-blocking javascripts

The most common culprit javascript, and a really great example for this is jQuery which is a javascript file that is used on a large percentage of webpages. It is very likely you are using it (find out with our tool if you are).
This javascript file is rather large, in fact it may very well be the largest file your webpage is loading to render your page.

jQuery is a popular javascript file, and is often used to do very little things like a fade in or out of an image for example. There is typically no reason to load jQuery before you load you your webpage yet the vast majority of pages are doing it.

If the thing you are using jQuery for happens below the fold thenthere is no reason to load it before it is needed. If you are loading it before, you are not following this pagespeed guideline and you are making your users wait.

To correct this requires that you change where the call for jQuery is made. This is done in the html of your webpage. The way most websites are currently calling jQuery is in the head of the document as shown below.

<head>
<meta name=description content="description here."/>
<title>title here</title>
<style>
styles here
</style>
<script src="jquery.js">
</script>
</head>

  

That call to jQuery (a rather large file) is made and has to be downloaded by the browser before anything else is shown on the page. This is bad. This is really really bad if the thing you are using jQuery is not even needed for the above the fold content as shown in above image.

An often used partial solution

Often the call to jQuery will be removed from the head of the document and moved to somewhere elese further down the page, as it is not needed until then. Unfortunately this isn‘t enough.

<!-- the things you don‘t need jquery for (most of your page) is here -->
<script src="jquery.js">
</script>
<!-- the thing you need jQuery for is here -->

  

True solution

To completely remove javascript from the rendering path it will need to deferred until after the page loads. I have a tutorial for this using the Google recommended solution that completely defers javascript.

To follow this well you need to know what your page loads and why it loads it

Anything your webpage calls costs your users more of their time. If you don‘t know what requests your webpage makes, you need to start knowing. jQuery is a good example because it is so common and such a large file (about 100kb). An all to common scenario is that a small webpage that is only 10kb is calling a large file like jQuery (which is ten times larger than the webpage itself) to do some mundane task like fade in some words on the page. You may have thought "hey that looks cool!" when you saw it, but is it cool enough to make your user wait ten times more time to see your page? the exact same effect could happen with CSS or smaller javascript.

I used jQuery as an example but I am not saying it is bad. The same things could be said of even commoner javascripts like Google analytics, or some third party javascripts that show widgets or even those social Facebook, Twitter buttons that people love so much.

Know what your page is using, and decide if it is worth making your visitors wait

  • The request tool on this site is a good way to see what your page is using.
  • To remove your render blocking javascript you must defer it.
时间: 2024-07-30 03:18:46

Render blocking javascripts的相关文章

页面加速优化

内联 CSS 优点 使用内联 CSS 可以减少浏览器去服务端去下载 CSS 文件 关键 CSS 内联到 HTML 文件中 缺点 CSS 文件没法被缓存 注意:该方法只适用于很小的 CSS 文件,如果你的 CSS 文件足够大以及复杂,应该使用外部 CSS 的方法. 优化 CSS 交付 优化策略 外部的 CSS 不要超过一个,大小应该小于 50k 对于下拉区域以上的内容,使用 style 标记内联小 CSS 到 HTML 不要使用 @import 调用 CSS 不要把 CSS 元素放在 HTML 的

PWA 渐进式实践 (3) - 用户体验 &amp; 性能

为了让我们的网站能达到更高的评分(咦,为什么变成刷分了),我们最后需要进行用户体验和性能的优化. 页面加载性能 我们需要尽可能把其他所有页面做成异步的,如: function getSubmitCase(nextState, callback) { require.ensure([], (require) => { callback(null, require('./containers/case/SubmitCasePage').default); }, 'SubmitCasePage');

网页性能优化指导--说得太好了,详细,具体,易理解,推荐看----Website Speed Optimization Guide for Google PageSpeed Rules

原链接地址:http://www.artzstudio.com/2016/07/website-speed-optimization-guide-for-google-pagespeed-rules/ Website Speed Optimization Guide for Google PageSpeed Rules By Dave Artz 1 week ago 6  534 0 Page Speed/Site speed is termed as the speed with which

Loading CSS without blocking render

The principles behind these techniques aren't new. Filament group, for example, have published great content on loading CSS and fonts. I've written this article to document my thoughts and ideas for loading non-blocking resources. The trick to trigge

SpringMVC异常_Could not resolve view with name &#39;javascripts/jquery-2.1.4&#39; in servlet with name &#39;springMVC&#39;

今天在编写代码的时候,自己页面中的按钮都无法点击,CSS样式也无法加载出来,查看之前的Spring MVC 的配置文件也是都正常,查看后台,发现如下错误 严重: Servlet.service() for servlet [springMVC] in context with path [/spring-idap-web] threw exception [Could not resolve view with name 'javascripts/jquery-2.1.4' in servlet

理解Vue中的Render渲染函数

VUE一般使用template来创建HTML,然后在有的时候,我们需要使用javascript来创建html,这时候我们需要使用render函数.比如如下我想要实现如下html: <div id="container"> <h1> <a href="#"> Hello world! </a> </h1> </div> 我们会如下使用: <!DOCTYPE html> <html

Android OpenGL ES零基础系列(一):理解GLSurfaceView,GLSurfaceView.Render的基本用法

转载请注明出处 前言 OpenGL ES是OpenGL的一个子集,是针对手机.PDA和游戏主机等嵌入式设备而设计的.该API由Khronos集团定义推广,Khronos是一个图形软硬件行业协会,该协会主要关注图形和多媒体方面的开放标准. 因此OpenGL ES作为第三方库被应用在android中. 到目前为止,OpenGL ES已经发展有了3个版本,OpenGL ES 1.0 , OpenGL ES 2.0 , OpenGL ES 3.0.其中OpenGL ES 1.0 是以OpenGL 1.3

[Preact] Use State and Props in the Component Render Function

Preact offers, in addition to the regular component API from React, the ability to access both props & state as function parameters to the render method. This lesson will cover an example of how to utilize this convenience along with how destructurin

ASP.NET重写Render 加载CSS样式文件和JS文件(切换CSS换皮肤)

网页换皮肤的方式有很多种,最简单的通常就是切换页面CSS,而CSS通常写在外部CSS文件里.那么切换CSS其实就是更换html里的link href路径.我在网上搜索了下. 一般有两种方式: 1.页面放一个Holder控件.然后用编程方式把当前用户的风格css link写入页面. 2.过反射机制,逐个控件设置css样式. 上面两种方式都挺麻烦的,第一种需要在每个页面上放一个holder控件,类似的做法还有把link标签加runat=server的做法,页面多了,都比较麻烦.第二种不用考虑了,性能