[读书笔记]高性能js-Ajax

本文探讨了现代Web开发中数据交换的三种主要方式:使用XMLHttpRequest进行标准的数据传输,利用script标签实现跨域获取JS文件,以及通过发送消息的方式,如Beacon API。深入讨论了GET与POST方法的区别与适用场景,以及如何利用缓存机制提高数据请求效率。

ajax is an async transferring information way.

three ways to exchange data in today.

1. use XMLHttpRequest,

normal way .but some attention. first ,xhr.readystate==3 means loading the message which is said streaming but ie not support it well.

also, for post and get.while send message to server not get something from it and you url is no more than 2048 characters,just use get method.

for the get method also cache info.other situation,use post method.

 

2 use script tag.

use this way can cross domain to get js.

var script=document.createElement('script');

script.src='a.js';

document.getelementbytagname('head')[0].appendChild('script');

function callback(jsonstring){

  var data=eval(jsonstring);

}

 

for this method,a.js must be executable js code.

for a.js ,it's callback({'a':1,"b":32});

 3 mxhr not very clear other time for search

 

send message.

two way .

one normal ajax get or post method.the other is beacons

var url='index.php';

var para=['stp=1','sdd=2'];

(new Image()).src=url+'?'.para.join('&');

by the way, server will not send anything to customer side. 

 

 

ajax profience.

use header in server side to last the expire day of request so ajax will not send other request to server and just use the cache.

all server script can set header .for php, it's  header('Expires:'.gmdate('D,d m y h:i:s').time()+$lifetime.'GMT');

转载于:https://www.cnblogs.com/wz0107/p/4954466.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值