Response.Buffer=True

不知道大家对Buffer了解多少,很多人对这个概念都比较模糊,尤其是在asp中。

很多初学者在编写asp程序时很少用到这条语句,下面我就来说说Buffer的用途以

及它在asp程序中的作用。
一、Buffer

Buffer从英文直译过来的意思是“缓冲区”,这里我们将它称为缓冲,因为它不

仅是个名词,还是个动词。
缓冲区是存储一系列的数据的地方,客户端所获得的数据可以从程序的执行结果

直接输出,也可以从缓冲区输出。但是这两种方式在速度上是有差异的:在web中

,当一个asp程序被请求的次数不多时,二者基本上没有什么差异,至少我们感觉

不出来。但是当有很多人请求一个asp程序时,速度可就不一样了。如果没有缓冲

区,那么每个请求asp程序的人的客户端所得到的结果都是asp程序执行一次所得

到的结果,而如果预先将asp程序缓冲,那么每个客户端所得到的结果就是缓冲区

的结果,不是执行一次程序的结果。比如有1000个用户同时访问一个asp页面,如

果这个asp程序没有缓冲,那么程序将被执行一千次,这样服务器的负荷就回加大

,从而导致客户端打开页面速度变慢;如果这个asp程序被缓冲了,那么结果就不

一样了,每个客户端直接从缓冲区获得数据,服务器将不会因为访问增加而增加

程序执行次数,因此客户端打开页面的速度也就比上一种情况要快。这就是

Buffer的好处。

二、如何将asp程序缓冲

这个问题其实很简单,只要在asp程序的第一行加上:
<% Response.Buffer = True %>
就可以了。
这句话的意思就是指明输出页面是否被缓冲,当属性值为True时,服务器将不会

向客户端发送任何信息,直到所有程序执行完或者遇到
<% Response.Flush %>或<% Response.End %>
语句,才会释放缓冲区的信息。


三、总结

Response的Buffer属性虽然能够提高页面显示速度,但是也要分什么情况。如果

你正在制作一个普通的个人主页,访问量不是很高,并且没有什么复杂的执行程

序,那么用不用这个属性就不是很重要,因为将数据缓冲也需要一段时间,只不

过我们感觉不到罢了;但是如果你正在制作一个大型论坛或者一个产品展示或其

他的商务站点,并且访问量很高,那么我建议在程序的第一行加入
<% Response.Buffer = True %>
这句话,因为这样能够让客户在有效的时间内获得更多的数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
function webAudio(options){ //public this.volume = parseInt(options.volume || 100) ; // 音量控制单元,值为Number类型,范围为0-100 this.url = options.url || '' ; // 音频资源url,值类型为String类型 this.autoPlay = !!options.autoPlay; // 是否加载完成自动播放,值类型为Boolean类型 this.loopPlay = !!options.loopPlay; // 是否循环播放,值类型为Boolean类型 //private this.buffer = null; this.context = null; this.sourceAudio = null; this.gainNode = null; this.loadReady = false; //初始化 this.init = function () { window.AudioContext = window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.msAudioContext; if(!AudioContext){ console.error("您的浏览器不支持HTML5 audio API"); return } this.context = new AudioContext(); this.loadResource(); } //下载音频资源 this.loadResource = function () { var _this = this; var xhr = new XMLHttpRequest(); xhr.open('GET',this.url,true); xhr.responseType = 'arraybuffer'; xhr.onload = function () { _this.context.decodeAudioData(xhr.response,function (buffer) { _this.buffer = buffer; _this.prepareAudio(); this.loadReady = true; }) } xhr.send(); } //是否自动播放 this.prepareAudio = function () { this.autoPlay ? this.startAudio() : ''; } //创建音频 this.createAudio = function () { this.sourceAudio = this.context.createBufferSource();//创建一个音频源 相当于是装音频的容器 this.sourceAudio.buffer = this.buffer;// 告诉音频源 播放哪一段音频 this.gainNode = this.context.createGain();//调节音量 this.sourceAudio.connect(this.gainNode); this.changeVolume();//声音 this.sourceAudio.loop = this.loopPlay;//循环 this.gainNode.connect(this.context.destination);// 连接到输出源 } //重新播放 this.startAudio = function () { this.createAudio(); this.sourceAudio.start(0);//开始播放 } //改变音量 this.changeVolume = function (num) { num = num || 0; this.gainNode.gain.value = (this.volume += num) / 100; } //播放转为暂停 this.pauseAudio = function () { this.gainNode.disconnect(this.context.destination) } //暂停转为播放 this.playAudio = function () { this.gainNode.connect(this.context.destination) } //停止播放 this.stopAudio = function () { this.sourceAudio.stop() } //减小声音 this.decVolume = function () { if(this.volume >= 10){ this.changeVolume(-10); } } //增大声音 this.ascVolume = function () { if(this.volume <= 90){ this.changeVolume(10); } } //静音 this.quietVolume = function () { this.gainNode.gain.value = 0; } //静音恢复 this.recoverVolume = function () { this.changeVolume() } //当前音量 this.getVolume = function () { return (this.gainNode.gain.value).toFixed(2) * 100; } this.init(); return this; } window.test = new webAudio({ volume:100, url:'1.mp3', autoPlay:true, loopPlay:true }); //控制台事件 var pauseEle = document.getElementById("pause"); pauseEle.onclick = function() { if (pauseEle.alt === 'Pause') { test.pauseAudio(); } else { test.playAudio(); } }增加播放暂停图片切换
最新发布
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值