【原】浅谈Firefox下的js、css、图片阻塞现象(一)
外部js文件阻塞body中的图片
以如下html为例:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> 外部JS文件阻塞图片 </title>
<script src="https://95598.gd.csg.cn/javascript/jquery-1.7.2.min.js" type="text/javascript"></script>
</head>
<body>
<img src="https://95598.gd.csg.cn/images/secImages/logo.gif" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/header_city_turn.png" width="50" height="21" alt="切换城市" />
<img src="https://95598.gd.csg.cn/images/secImages/customer_service.jpg" width="150" height="150" />
<img src="https://95598.gd.csg.cn/activity/images/wel_act.jpg" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_2.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_3.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_top.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t1.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t2.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t3.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a1.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a2.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a3.png" width="60" height="60" alt=""/>
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a4.png" width="64" height="64" alt="" />
</body>
</html>
script 在<head>中
经过firebug网络分析:

图 1-1
观察图1-1可以得出如下两个结论:
1.浏览器针对请求(如图片)是并发处理的,在IP、端口号相同时,Firefox的默认并发请求数是6(HTTP1.1和HTTP1.0的并发请求数因浏览器版本的不同而数量不同),可以看到6张图片是同时从服务器下载
2.js文件加载完后,中间约有0.1s的空闲时间,这段时间浏览器没有进行任何操作,这一现象可以称作阻塞,外部js文件阻塞了body中的img请求(在IE下不存在阻塞)
如果将<script>块置于img中间,也会产生阻塞(在IE下不存在阻塞)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> 外部JS文件阻塞图片 </title>
</head>
<body>
<img src="https://95598.gd.csg.cn/images/secImages/logo.gif" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/header_city_turn.png" width="50" height="21" alt="切换城市" />
<script src="https://95598.gd.csg.cn/javascript/jquery-1.7.2.min.js" type="text/javascript"></script>
<img src="https://95598.gd.csg.cn/images/secImages/customer_service.jpg" width="150" height="150" />
<img src="https://95598.gd.csg.cn/activity/images/wel_act.jpg" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_2.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_3.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_top.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t1.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t2.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t3.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a1.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a2.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a3.png" width="60" height="60" alt=""/>
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a4.png" width="64" height="64" alt="" />
</body>
</html>
scipt置于中间

图 1-2
如果将外部js文件置于</body>前,则可以消除阻塞现象
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> 外部JS文件阻塞图片 </title>
</head>
<body>
<img src="https://95598.gd.csg.cn/images/secImages/logo.gif" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/header_city_turn.png" width="50" height="21" alt="切换城市" />
<img src="https://95598.gd.csg.cn/images/secImages/customer_service.jpg" width="150" height="150" />
<img src="https://95598.gd.csg.cn/activity/images/wel_act.jpg" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_2.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_3.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/sidebar_top.png" width="48" height="48"/>
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t1.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t2.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/electricity_t3.png" width="169" height="53" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a1.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a2.png" width="64" height="64" alt="" />
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a3.png" width="60" height="60" alt=""/>
<img src="https://95598.gd.csg.cn/images/secImages/icon_big_a4.png" width="64" height="64" alt="" />
<script src="https://95598.gd.csg.cn/javascript/jquery-1.7.2.min.js" type="text/javascript"></script>
</body>
</html>
调整script位置到末尾

图 1-3
对比图1-1、图1-2、图1-3,同样的文件加载,只是顺序上的不同,图1-3的加载时间比图1-1、图1-2节省了约0.1s(测试结果有一定随机性)
【原】浅谈Firefox下的js、css、图片阻塞现象(一)的更多相关文章
- [原创]浅谈NT下Ring3无驱进入Ring0的方法
原文链接:浅谈NT下Ring3无驱进入Ring0的方法 (测试环境:Windows 2000 SP4,Windows XP SP2.Windows 2003 未测试) 在NT下无驱进入Ring0是一个 ...
- 浅谈 IE下innerHTML导致的问题
原文:浅谈 IE下innerHTML导致的问题 先来看个demo吧: <!DOCTYPE html> <html> <head> <meta charset= ...
- 浅谈Linux下/etc/passwd文件
浅谈Linux 下/etc/passwd文件 看过了很多渗透测试的文章,发现在很多文章中都会有/etc/passwd这个文件,那么,这个文件中到底有些什么内容呢?下面我们来详细的介绍一下. 在Linu ...
- []转帖] 浅谈Linux下的五种I/O模型
浅谈Linux下的五种I/O模型 https://www.cnblogs.com/chy2055/p/5220793.html 一.关于I/O模型的引出 我们都知道,为了OS的安全性等的考虑,进程是 ...
- 浅谈Vue下的components模板
浅谈Vue下的components模板在我们越来越深入Vue时,我们会发现我们对HTML代码的工程量会越来越少,今天我们来谈谈Vue下的 components模板的 初步使用方法与 应用 我们先来简单 ...
- 浅谈网络爬虫爬js动态加载网页(二)
没错,最后我还是使用了Selenium,去实现上一篇我所说的问题,别的没有试,只试了一下firefox的引擎,总体效果对我来说还是可以接受的. 继续昨天的话题,既然要实现上篇所说的问题,那么就需要一个 ...
- 浅谈Linux下如何修改IP
linux 下命令之浅谈//cd .. //返回上一级//创建文件夹touch test.txt//Linux不区分大小写//往一个文件中追加内容echo "****" > ...
- 转:利用node压缩、合并js,css,图片
1.安装nodejs http://nodejs.org/ 2.安装各自的node package js我用的是UglifyJS github地址:https://github.com/mishoo/ ...
- 浅谈时钟的生成(js手写代码)
在生成时钟的过程中自己想到布置表盘的写法由这么几种: 当然利用那种模式都可以实现,所以我们要用一个最好理解,代码有相对简便的方法实现 1.利用三角函数 用js在三角函数布置表盘的过程中有遇见到这种情况 ...
随机推荐
- SPI Flash
使用了MX25L512的SPI接口的Flash 电路连接图: 总的大小512kb,即64kB,sector的大小为256 Bytes,block的大小为4k Bytes 调试时出现的问题: 1.Fla ...
- Linux软件大全
https://www.linux-apps.com/browse/cat/239/ord/latest/http://www.cnblogs.com/riskyer/p/3262745.htmlht ...
- W5300E01-ARM 交叉编译器(Cross Compiler)用户手册
W5300E01-ARM是基于W5300的ARM功能测试评估板: 1 简介 当用户的开发环境与目标系统不同时就会用到交叉编译器. 例如,当开发基于ARM的嵌入式系统时,用户就需要在电脑上写出 ...
- logstash indexer和shipper的配置
[elk@zjtest7-frontend config]$ cat logstash_agent.conf input { file { type => "zj_nginx_acce ...
- C语言入门(17)——C语言数组应用的一个实例
本篇通过一个实例介绍使用数组的一些基本模式.问题是这样的:首先生成一列0-9的随机数保存在数组中,然后统计其中每个数字出现的次数并打印,检查这些数字的随机性如何.随机数在某些场合(例如游戏程序)中是非 ...
- API之IP地址查询---权威的IP地址查询接口集合
原文地址:http://yushine.iteye.com/blog/1717586 推荐实用IP138 http://www.baidu.com/s?wd=IP&rsv_spt=1& ...
- 优步北京B组(8月10日-8月16日奖励规则)
奖励政策: [优步北京B组] 定义为2015年7月20日前激活的部分司机(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机( ...
- #include <stdbool.h>
可以使用bool和true.false 输出是1或者0 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdb ...
- CSS实现倒影-------Day80
发现这个功能的时候非常开心,结果不想居然是个残次品,让我不禁想起了"天龙八部"上段誉的六脉神剑,在这个浏览器上能够.在还有一个上就无论了啊,时灵时不灵的,只是有总比没有要来的好,一 ...
- Sizzle一步步实现所有功能(层级选择)
第二步:实现Sizzle("el,el,el..."),Sizzle("el > el"),Sizzle("el el"),Sizzl ...