Modern web data transmission technology and data formats

A data transmission technology

1、xhrHttpRequest(XHR)

Advantages: flexible operation, control, and can operate the http header and body.

Disadvantages: cross-domain requests a problem, the low version of the browser does not support the "flow" of data transmission.

Precautions: get request can be cached. For small amounts of data for a request, get request to transmit data faster, post suitable for sending large amounts of data (url parameter is greater than when 2048 characters).

About cross-domain Ajax request issue : cross-domain resource sharing CORS, CORS is a W3C standard, stands for "Cross-Origin Resource Sharing" (Cross-origin resource sharing) . Once AJAX browser cross-origin request, it will automatically add some additional header information, and sometimes more than once a additional request (options), but the user does not have feelings. Therefore, communication is the key to achieving CORS server. CORS long as the server implements the interface, you can communicate across the source. It allows the browser to cross the source server, issued a request XMLHttpRequest, which overcomes the limitations of AJAX only homologous use.


2, the dynamic script injection

Advantage: cross-domain. Execution speed, since the content data executed directly as a script, not by parsing a string (Ajax request requires parsing the data string)

Disadvantages: limited control request, the data must be enclosed within a function, the introduction of data that is hidden from external sources.


3、multiple XHR

Advantages: a http request can get a lot of resources. Resources may be separately processed by the data "flow" (readystate listen to the data stream 3)

Disadvantages: transmission rules and server complex definition data. The requested data can not be cached.


Second, the data format

1、XML

Benefits: General.

Disadvantages: heavy data structure. Resolve slow.

2、JSON

Benefits: General. And javascript syntax closely. Structure is more clear and simple.

3 JSONP

Advantage: When the amount of data they can use JSONP form of data, dynamic script injection techniques, to speed up execution, because the data does not need to be parsed JSONP, can be executed directly. And be able to break out across domains.

4, since the data format is defined

And the server is defined by a more convenient form plaintext data (using simple delimiter) to transmit data, but also can greatly reduce the time data is parsed.


Today most data requests mainstream technology is still Ajax, with an http server cache settings, you can better enhance performance. When the face of requests and process large amounts of data, consider the data format or custom use JSONP.

Guess you like

Origin blog.csdn.net/weixin_34309543/article/details/91398370