8. 客户端缓存
both HTTP and HTTPS
http和https的资源都可以被缓存
给所有静态资源设置缓存头
避免不必要重复,Expires和Cache-Control只需二选一,
Last-Mofidied和Etag同理
建议使用Expires& Last-Modified,因为他们更广泛被支持
Expires头的值至少一个月,最好是一年,不要超过一年,因
为这个违反RFC标准
使用时间戳更新缓存资源
在URL中加入一个get请求参数,如?v=201314
Make the Web Faster-缓存的优化-客户端缓存
21. 异步加载脚本
异步加载指浏览器在下载执行 js 同时,还会继续进行
后续页面的处理
Make the Web Faster-减少往返延时-异步加载脚本
<script>
var node = document.createElement('script');
node.type = 'text/javascript';
node.async = true;
node.src = 'example.js';
// Now insert the node into the DOM, perhaps using insertBefore()
</script>
28. 延迟加载
延迟加载并不一定减少总下载数据,但可以提升初始
加载的体验
Make the Web Faster-优化服务器返回数据-延迟加载
<script>
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "deferredfunctions.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>
39. 参考文献
Make the web faster
https://developers.google.com/speed/docs/best-
practices/rtt?hl=fr
浏览器支持一览
http://www.browserscope.org/?category=network&v=top
异步加载
http://www.cnblogs.com/tiwlin/archive/2011/12/26/2302554.
html
Best Practices for Speeding Up Your Web Site
http://developer.yahoo.com/performance/rules.html
Writing Efficient CSS
https://developer.mozilla.org/en-
US/docs/Writing_Efficient_CSS
它山之石可以攻玉