bing zhang
前端新兵,关注nodejs、TDD、自动化构建 Github:https://github.com/uc2dabing
- 前端优化 : 80% - 90%的时间用来下载页面资源以及浏览器渲染
- 后端优化 : 10% - 20%的时间生成html内容
相同域名下,主流浏览器的并发下载量
静态资源,不跟应用同域名,最好根域都不同。
<div id= "enter">
<img src="images/common.png" alt="" />
<a href=""> 换 行</a ></div>
<div id= "noenter"><img src="images/common.png" alt="" /><a href=""> 换 行</a ></div>
<div id= "enter">
<img src="images/common.png" alt="" />
<a href="">换行</a ></div>
<div id= "noenter"><img src="images/common.png" alt="" /><a href=""> 没有换行,有空格</a ></div>
<div id= "enter">
<img src="images/common.png" alt="" />
<a href="">换行</a ></div>
<div id= "noenter"><img src="images/common.png" alt="" /><a href="">没有换行</a ></div>
tips:
原始方式:
<img src="icon-new.gif" />
切图调用方式:
.icon-new{ background-position: -38px 0px; background: url(/img/icon.gif); } .icon-del{ background-position: 30px 0px; background: url(/img/icon.gif); } <i class="icon-del"></i> <i class="icon-new"></i>
Last-Modified、If-Modified-Since浏览器会发起请求,服务器返回304。Expires,Cache-Control直接不发起请求,减少负载,两者F5、ctrl+F2无效。Cache-Control会重写掉Expires
两者互斥css放头部减少 “白屏”、“无脚本闪烁”、js放尾部减少 “白屏”、“阻塞其它资源下载”
<html>
<head>
<title>常用html架构</title>
<link rel="stylesheet" type="text/css" href="app.css" />
</head>
<body>
<div id="wrapper">
<header></header>
<div id="content"></div>
<footer></footer>
</div>
<script type="text/javascript" src="lib.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>
By bing zhang
html、js、css压缩、合并;浏览器加载模型;http缓存实现;