gor
Gor is a simple http traffic replication tool written in Go. Its main goal is to replay traffic from production servers to staging and dev environments.
主要的使用命令:
- 使用1个Gor Instance来进行listen和replay(有延迟)
sudo gor --input-raw :80 --output-http "http://staging.com"
这部分的功能好像有延迟的问题,需要考虑
- 离线进行replay(推荐)
# write to file
gor --input-raw :80 --output-file requests.gor
# read from file
gor --input-file requests.gor --output-http "http://staging.com"
- 采用单独的replay server来进行转存(未通过)
# Replay server (replay.local).
gor --input-tcp replay.local:28020 --output-http http://staging.com
# Run on servers where you want to catch traffic. You can run it on each `web` machine.
sudo gor --input-raw :80 --output-tcp replay.local:28020
当然,这块还有更多的扩展
jquery.each
We can break the $.each() loop at a particular iteration by making the callback function return false. Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.
(function(){
// 結束循環(即break)
jQuery.each(aOptionList, function(index, option){
if (option.innerHTML === "stop") {
return false; // 返回false即break掉each循環
}
// magic
});
// 繼續下一個循環(即continue)
jQuery.each(aOptionList, function(index, option){
if (option.innerHTML === "stop") {
return true; // 返回任意非false值
}
// magic
});
}());
ajax过程
- 创建XMLHttpRequest对象,也就是创建一个异步调用对象.
- 创建一个新的HTTP请求,并指定该HTTP请求的方法、URL及验证信息.
- 设置响应HTTP请求状态变化的函数.
- 发送HTTP请求.
- 获取异步调用返回的数据.
- 使用JavaScript和DOM实现局部刷新.
浏览器并发
6个并发
js闭包
- 函数嵌套函数
- 函数内部可以引用外部的参数和变量
- 参数和变量不会被垃圾回收机制回收
好处部分:
- 希望一个变量长期驻扎在内存中
- 避免全局变量的污染
- 私有成员的存在
<script>
function outer(){
var x=10;
return function(){ //函数嵌套函数
x++;
alert(x);
}
}
var y = outer(); //外部函数赋给变量y;
y(); //y函数调用一次,结果为11,相当于outer()();
y(); //y函数调用第二次,结果为12,实现了累加
</script>