[·Òë]High Performance JavaScript(030)
µÚʮՠTools ¹¤¾ß
Having the right software is essential for identifying bottlenecks in both the loading and running of scripts. A number of browser vendors and large-scale websites have shared techniques and tools to help make the Web faster and more efficient. This chapter focuses on some of the free tools available for:
µ±È·¶¨½Å±¾¼ÓÔØºÍÔËÐÐʱµÄÆ¿¾±ËùÔÚʱ£¬ºÏÊֵŤ¾ßÊDZز»¿ÉÉٵġ£Ðí¶àä¯ÀÀÆ÷³§É̺ʹóÐÍÍøÕ¾·ÖÏíÁËһЩ¼¼ÊõºÍ¹¤¾ß£¬°ïÖú¿ª·¢ÕßÊ¹ÍøÒ³¸ü¿ì£¬Ð§Âʸü¸ß¡£±¾Õ¹Ø×¢ÓÚÕâЩÃâ·Ñ¹¤¾ß£º
Profiling ÐÔÄÜ·ÖÎö
Timing various functions and operations during script execution to identify areas for optimization
Ôڽű¾ÔËÐÐÆÚ¶¨Ê±Ö´Ðв»Í¬º¯ÊýºÍ²Ù×÷£¬ÕÒ³öÐèÒªÓÅ»¯µÄ²¿·Ö
Network analysis ÍøÂç·ÖÎö
Examining the loading of images, stylesheets, and scripts and their effect on overall page load and rendering
¼ì²éͼƬ£¬Ñùʽ±í£¬ºÍ½Å±¾µÄ¼ÓÔØ¹ý³Ì£¬»ã±¨ËüÃǶÔÕû¸öÒ³Ãæ¼ÓÔØºÍäÖȾµÄÓ°Ïì
When a particular script or application is performing less than optimally, a profiler can help prioritize areas for optimization. This can get tricky because of the range of supported browsers, but many vendors now provide a profiler along with their debugging tools. In some cases, performance issues may be specific to a particular browser; other times, the symptoms may occur across multiple browsers. Keep in mind that the optimizations applied to one browser might benefit other browsers, but they might have the opposite effect as well. Rather than assuming which functions or operations are slow, profilers ensure that optimization time is spent on the slowest areas of the system that affect the most browsers.
µ±Ò»¸öÌØ¶¨µÄ½Å±¾»òÓ¦ÓóÌÐòûÓдﵽ×îÓÅ״̬ʱ£¬Ò»¸öÐÔÄÜ·ÖÎöÆ÷ÓÐÖúÓÚ°²ÅÅÓÅ»¯¹¤×÷µÄÏȺó´ÎÐò¡£²»¹ý£¬ÒòΪä¯ÀÀÆ÷Ö§³ÖµÄ·¶Î§²»Í¬£¬Õâ¿ÉÄܱäµÃºÜÂé·³£¬µ«Ðí¶à³§ÉÌÔÚËûÃǵĵ÷ÊÔ¹¤¾ßÖÐÌṩÁËÐÔÄÜ·ÖÎöÆ÷¡£ÓÐЩÇé¿öÏ£¬ÐÔÄÜÎÊÌâ¿ÉÄÜÓëÌØ¶¨ä¯ÀÀÆ÷
Ïà¹ØÎĵµ£º
±¾ÎÄÖ÷ÒªÊdzöÓÚÓÐÅóÓÑʹÓÃÎÒÔÀ´Ð´µÄautocompleteµÄJS¿Ø¼þ¡£µ±Êý¾ÝÁ¿´óµÄʱºò£¬»á³öÏÖЧÂʼ«ÆäÂýµÄÇé¿ö£¬ÎÒÔÚÕâ¶Îʱ¼ä×ö³öµÄһЩ²âÊÔÒ²¼°Ò»Ð©¾Ñ飬Óë´ó¼Ò·ÖÏí£¬Èç¹ûÓдíµÄµØ·½£¬»¹ÇëÖ¸³ö¡£
¾¹ý²âÊÔ£¬ÎÒÃǻᷢÏÖÈçϵÄÇé¿ö»òÕß˵µÄ½áÂÛ£¬Èç¹ûÄúµÄ²âÊÔ½á¹ûÓëÎҵIJ»·û£¬Çë˵Ã÷ÔÒò£¬ÒÔ±ãÏ໥ѧϰ¡£
1£©µ±Ò»¸ö½Ï´óµÄHTML×Ö· ......
Conditionals Ìõ¼þ±í´ïʽ
Similar in nature to loops, conditionals determine how execution flows through JavaScript. The traditional argument of whether to use if-else statements or a switch statement applies to JavaScript just as it does to other languages. Since different b ......
µÚ°ËÕ Programming Practices ±à³Ìʵ¼ù
Every programming language has pain points and inefficient patterns that develop over time. The appearance of these traits occurs as people migrate to the language and start pushing its boundaries. Since 2005, when the term "Ajax" ......