In the best practices of the Yahoo system, it is recommended to output static content as soon as possible and call flush after the head so that the browser can load static resources as soon as possible, including scripts, styles, images (external CEPT, css, and image are usually in the form of external links), etc. if there are multiple data sources in the background or... syntaxHighlighter. in the best practices of the Yahoo system, we recommend that you output static content as early as possible and call flush after the head so that the browser can load static resources as soon as possible, including scripts, styles, images (usually external links, css, and images), etc. if there are multiple data sources or APIs in the background that need to be called, try to make one output, through js, the front-end page is assembled to optimize the user experience. the user waiting time is the shortest wooden board in the barrel.
The following is a reference:
Flush the Buffer Early
Tag: server
When users request a page, it can take anywhere from 200 to 500 ms for the backend server to stitch together the HTML page. during this time, the browser is idle as it waits for the data to arrive. in PHP you have the function flush (). it allows you to send your partially ready HTML response to the browser so that the browser can start fetching components while your backend is busy with the rest of the HTML page. the benefit is mainly seen on busy backends or light frontends.
A good place to consider flushing is right after the HEAD because the HTML for the head is usually easier to produce and it allows you to include any CSS and JavaScript files for the browser to start fetching in parallel while the backend is still processing.
Example:
...
...
Facebook's BigPipe technology has implemented this idea more specifically. the general idea is to break down a webpage into small pieces called Pagelets, then, you can establish pipelines through Web servers and browsers and manage their operations at different stages.
Perform a small test in php,
'; Ob_flush (); flush (); sleep (2); echo "B";?>
The results can be seen in ie (), regardless of the size of the output content, you can see the effect, "B" output in 2 seconds, in firefox and chrome, the two texts are displayed in 2 seconds, indicating that the browser has been cached. after experiment, the cache size is 1024, which is exactly 1 k, which is also the optimization of the browser. We can see from the returned header that the returned package does not go through gzip during multipart output.
Wireshark can be seen that the background output is indeed chunked one by one. it seems that the browser has done the work and guessed that the cache size should be 1024B or MTU size (more than B points, depending on network conditions ), when the first output increases to 1024, chrome and firefox both started to perform normally. the js, css, and images on the page started to be loaded after the first download.
Questions to consider:
1. transmission efficiency: adjust the MTU size based on the maximum number of items transmitted at a time;
2. synchronous loading: The first item is sent. you can load it synchronously as much as possible. Note that different browsers can load the number of domain names synchronously. you need to consider loading blocks by javascript, for content that does not need to be executed immediately, you can add defer or simply comment out the content and wait for the page to complete eval;
3. applicability: any technology has its own application scenarios. it is more suitable for applications that need to access multiple APIs in the background, such as social websites, the search and other functions are displayed in about MS, and pure play technology is meaningless. the more chunked is, the better. it is appropriate. similar works are best combined;
4. it is best to pair ob_flush and flush. in some cases, flush is ineffective.
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