Javascript 异步加载详解

本文总结一下浏览器在 javascript 的加载方式。

关键词:异步加载 async loading, 延迟加载 lazy loading, 延迟执行 lazy execution, async 属性, defer 属性

一、同步加载与异步加载的形式

1. 同步加载

我们平时最常使用的就是这种同步加载形式:

1
<script src="http://yourdomain.com/script.js"></script>

同步模式,又称阻塞模式,会阻止浏览器的后续处理,停止了后续的解析,因此停止了后续的文件加载(如图像)、渲染、代码执行。
js之所以要同步执行,是因为js中可能有输出document内容、修改dom、重定向等行为,所以默认同步执行才是安全的。
以前的一般建议是把<script>放在页面末尾</body>之前,这样尽可能减少这种阻塞行为,而先让页面展示出来。
简单说:加载的网络timeline是瀑布模型,而异步加载的timeline是并发模型。

Read More

Share Comments

MySql data analysis notes

本文随时笔记随时更新

Statics by day

1
2
3
SELECT date_format(time, "%Y-%m-%d"), COUNT(*)
FROM zika_news.news_entry
GROUP BY date_format(time, "%Y-%m-%d");

Where time is the field in your data table, which its data type is DateTime. %Y-%m-%d means Year-Month-Day.

View Output
date_format(time, “%Y-%m-%d”) count(*)
2016-08-05 352
2016-08-06 179
2016-08-08 61
Server Code
1
2
3
4
5
6
7
8
9
10
11
12
Dim dt As DataTable = mysql.Fetch(SQL).Tables(0)
Dim data As date_count() <=

From row As DataRow
In dt.Rows
Select dd = New date_count With {
.date = CStr(row(MySqlREST.[date])),
.count = CInt(row(MySqlREST.count))
}
Order By dd.date Ascending

Call response.WriteJSON(data)
JSON output Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[
{
"count": 84,
"date": "2016-07-08"
},
{
"count": 141,
"date": "2016-07-09"
},
{
"count": 33,
"date": "2016-07-10"
},
{
"count": 41,
"date": "2016-07-11"
}
]

Read More

Share Comments

Network canvas in 3D

3D network in movie '007 Skyfall (2012)'

In this , there are two problem:

  • 3D rotation
  • 3D Projection

Read More

Share Comments

PDB molecular viewer

Reading the pdb model file:

1
2
3
Imports SMRUCC.genomics.Data.RCSB.PDB

Dim pdb As PDB = PDB.Load(path)
Share Comments

为什么我们瞧不起土狗?

不是狗土,是你土。

中国的语言文字是美丽丰富的,但却没能给中国土狗取一个名字。
不是已经说了叫土狗吗?柴狗、黄狗、草狗、中华田园犬,不都是名字?

不是。

Read More

Share Comments

Voyageur

Voyageur

Voyageur

歌手: Enigma
发行时间:2005-04-11
发行公司: Virgin Germany

Read More

Share Comments

The Screen Behind The Mirror

The Screen Behind The Mirror

The Screen Behind The Mirror

歌手: Enigma
发行时间:2004-10-11
发行公司: Virgin Germany

Read More

Share Comments

Calculating F-statistics from genotypic data

CLI_tools source code on github: pairwise.fst

Genotype
Populations AA Aa aa
Subpopulation 1 125 250 125
Subpopulation 2 50 30 20
Subpopulation 3 100 500 400

N (number of individuals genotyped. The sum of each of the rows in the table above):

1
2
3
Population 1:   500
Population 2: 100
Population 3: 1,000

Remember that the number of alleles is TWICE the number of genotypes.

Read More

Share Comments

MCMXC, A.D.

MCMXC, A.D.

MCMXC, A.D.

歌手: Enigma
发行时间:2006-11-28
发行公司: Capitol Catalog

Read More

Share Comments

R语言 假设检验(非参数) 学习笔记

1. 皮尔森拟合优度塔防检验

  • 假设H0:总体具有某分布F
  • 备择假设H1:总体不具有该分布。

我们将数轴分成若干个区间,所抽取的样本会分布在这些区间中。在原假设成立的条件下,我们便知道每个区间包含样本的个数的期望值。用实际值Ni与期望值Npi可以构造统计量K。皮尔森证明,n趋向于无穷时,k收敛于m-1的塔防分布m为我们分组的个数。有了这个分布,我们就可以做假设检验。

Read More

Share Comments