High-performance JavaScript programming (repetition 2)

Source: Internet
Author: User
Tags repetition script tag

----------------------------------------------

1. Request data

There are 5 commonly used techniques for requesting data from the server: Xmlhttprequest,dynamic script tag insertion (dynamic script tag insertion), Iframes,comet,multiparty XHR (Multi-part XHR);

(1) XHR: Generally with get and post requests, when the URL parameter length exceeds 2048 characters, only use post to submit data, because IE restricts the length of the URL, too long will cause the request is truncated;

(2) Dynamic script insertion: Dynamic script insertion provides less control than it can be; You cannot send a message header by request; The parameter can only be passed by a get method; You cannot set the request timeout or retry; in fact, you don't need to know if it failed. You must wait until all data is returned before you can access them. ----namely: JSONP

(3) Image tag simulation, usually just send data to the server, do not need a lot of return;

2: Caching (Cache)

(1) On the server side, set the HTTP header to ensure that the return message will be cached in the browser;

(2) On the client side, cache the acquired data locally; Do not request the same data multiple times;

The first technology is easiest to set up and maintain, and the second gives you the greatest degree of control;

Set HTTP headers;

If you want AJAX messages to be cached by the browser, you must initiate a GET request, and you must send the correct HTTP in the appropriate message, and the expires header tells the browser how long the response message should be cached;

--------------------------------------------------------------------------------------------------------------- -------------------------------------

When a Web browser requests a resource, it usually sends a accept-encoding HTTP header to let the Web server know what type of encoding is supported by the transport, which allows the document to compress to get faster speed, thereby improving the user experience ; accept-encoding Range: Gzip,compress,deflate and identity

--------------------------------------------------------------------------------------------------------------- --------------------------------------

Use content delivery Network CDN;

< finish >

High-performance JavaScript programming (repetition 2)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.