Web application optimization skills

Source: Internet
Author: User

Author: Fenng | reprinted. The original source and author information and copyright statement must be indicated in hyperlink form during reprinting.
Web: http://www.dbanotes.net/web/flickr_web_tech.html
Cal Henderson is one of the developers of the famous Flickr website. in an article titled Serving JavaScript Fast, he introduced the techniques used to optimize the applications of the Flickr site, which has benefited a lot after reading it. "chew on others' Tips" to summarize the main content of this article.

Flickr is a representative site of Web 2.0. In addition to content Optimization for general Web sites, the network problems also require flexible processing of the complexity of deployment and distribution after frequent changes in JavaScript and CSS.

The first problem facing the policy of setting the file size is to put all JavaScript and CSS in one file, or split it into multiple files? From the perspective of reducing network requests, the former is better than the latter. However, from the perspective of parallelism, by default, both IE and Firefox can only request two resources from one domain at the same time. this will bring a poor user experience in many cases-you must download all the files before you can see a decent page. flickr adopts a compromise-JavaScript and CSS are divided into multiple sub-files when the number of files is as small as possible. this brings complexity to the development, but the performance gains are huge.

There is no doubt about the compression optimization problem. compressing site content is a common Web optimization method. but not always achieve the desired results. the reason is that the mod-gzip module not only consumes server-side CPU resources, but also client-side CPU resources. in addition, the temporary files created after the mod_gzip file is compressed are stored on the disk, which may cause serious disk IO problems. flickr uses the mod_deflate module supported by Httpd 2.x and later. all compression operations are performed in the memory. mod_deflate is unavailable in Httpd 1.x, but the performance can be indirectly improved by creating a ramdisk.

Of course, mod_gzip is not useless. It is good for pre-compressed files. in addition, when using compression, you should also pay attention to the policy. there is no need to compress image files (there are a lot of Flickr images, and compression is not good ). flickr only compresses JavaScript and CSS. the new version of mod_gzip can automatically process pre-compressed files by configuring the mod_gzip_update_static option. cal also pointed out that this feature may cause problems in some earlier browsers.

Another major means of compression is content compression. for JavaScript, you can use tips such as reducing comments, combining spaces, and using compact syntaxes (all Google scripts are very hard to read and compact, with similar ideas ). of course, the JavaScript processed in this way may contain a lot of parentheses that are not easy to parse. Flickr uses the Dojo Compressor to build the parsing tree. Dojo Compressor has low overhead and is transparent to end users. the JavaScript processing method has been introduced, while CSS processing is relatively simple. A simple regular expression is used to replace multiple spaces with a single space character. A maximum compression ratio of 50% is obtained.

The optimization of Caching by the developers of Flickr makes full use of the Etag and Last-Modified mechanisms defined in the Http 1.1 Standard to improve the efficiency of Caching. it is worth noting that Cal introduces an e-Tag tips for Server Load balancer. you can set Apache to get the E-Tag through the file adjustment time and file size. By default, Apache obtains the e-Tag through the file node. Of course, this is not perfect, because it will affect if-modified-since.

The flexible use of mod_rewrite is said to be a Daily Build of the Flickr website application (Daily Build ). I am afraid this is unimaginable if there is no flexible mechanism. In addition, content modification and synchronization at sites such as Flickr are a headache. Their powerful tool is the flexible use of mod_rewrite. By configuring URL rewriting rules, you can easily switch to different environments. It sounds simple, but it's easy to do without some Web technical skills ?!

Through the use of these main methods, we can see the high performance of the network.


BTW: because there are no servers in China, the speed of access by users in mainland China should not be mentioned :(

-- End.

This [Web application optimization tips for developers of Flickr] comes from dbanotes.net

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.