Use the Fast Parts ʹÓÃËٶȿìµÄ²¿·Ö
Even though JavaScript is often blamed for being slow, there are parts of the language that are incredibly fast. This should come as no surprise, since JavaScript engines are built in lower-level languages and are therefore compiled. Though it's easy to blame the engine when JavaScript appears slow, the engine is typically the fastest part of the process; it's your code that is actually running slowly. There are parts of the engine that are much faster than others because they allow you to bypass the slow parts.
ËäÈ»JavaScript¾³£±»Ö¸Ôð»ºÂý£¬È»¶ø´ËÓïÑÔµÄijЩ²¿·Ö¾ßÓÐÄÑÒÔÖÃÐŵĿìËÙ¡£Õâ²»×ãΪÆæÒòΪJavaScriptÒýÇæÓɵͼ¶ÓïÑÔ¹¹½¨¡£ËäÈ»JavaScriptËÙ¶ÈÂýºÜÈÝÒ×±»¹é¾ÌÓÚÒýÇ棬Ȼ¶øÒýÇæͨ³£ÊÇ´¦Àí¹ý³ÌÖÐ×î¿ìµÄ²¿·Ö£¬Êµ¼ÊÉÏËÙ¶ÈÂýµÄÊÇÄãµÄ´úÂë¡£ÒýÇæµÄijЩ²¿·Ö±ÈÆäËü²¿·Ö¿ìºÜ¶à£¬ÒòΪËüÃÇÔÊÐíÄãÈƹýËÙ¶ÈÂýµÄ²¿·Ö¡£
Bitwise Operators λ²Ù×÷ÔËËã·û
Bitwise operators are one of the most frequently misunderstoo ......
µÚ¾ÅÕÂ
Building and Deploying High-Performance JavaScript Applications
´´½¨²¢²¿Êð¸ßÐÔÄÜJavaScriptÓ¦ÓóÌÐò
According to a 2007 study by Yahoo!'s Exceptional Performance team, 40%–60% of Yahoo!'s users have an empty cache experience, and about 20% of all page views are done with an empty cache (http://yuiblog.com/blog/2007/01/04/performance-research-part-2/). In addition, another more recent study by the Yahoo! Search team, which was independently confirmed by Steve Souders of Google, indicates that roughly 15% of the content delivered by large websites in the United States is served uncompressed.
¸ù¾ÝYahoo!׿ԽÐÔÄÜÍŶÓÔÚ2007Äê½øÐеÄÑо¿£¬40%-60%µÄYahoo!Óû§Ã»ÓÐʹÓûº´æµÄ¾Ñ飬´óÔ¼20%Ò³ÃæÊÓͼ²»Ê¹Óûº´æ£¨http://yuiblog.com/blog/2007/01/04/performance-research-part-2/£©¡£ÁíÍ⣬ÓÉYahoo!Ñо¿Ð¡×é·¢ÏÖ£¬²¢ÓÉGoogleµÄSteve SoudersËù֤ʵµÄÒ»Ïî×îÐÂÑо¿±íÃ÷£¬´óÔ¼15%µÄÃÀ¹ú´óÐÍÍøÕ¾ËùÌṩµÄÄÚÈÝûÓÐѹËõ¡£
These facts emphasize the need ......
JavaScript Minification JavaScript½ô´Õ
JavaScript minification is the process by which a JavaScript file is stripped of everything that does not contribute to its execution. This includes comments and unnecessary whitespace. The process typically reduces the file size by half, resulting in faster downloads, and encourages programmers to write better, more extensive inline documentation.
JavaScript½ô´ÕÖ¸µÄÊÇÌÞ³ýÒ»¸öJavaScriptÎļþÖÐÒ»ÇÐÔËÐÐÎÞ¹ØÄÚÈݵĹý³Ì¡£°üÀ¨×¢ÊͺͲ»±ØÒªµÄ¿Õ¸ñ¡£¸Ã´¦Àíͨ³£¿É½«Îļþ³ß´çËõ¼õµ½Ò»°ë£¬Æä½á¹ûÊÇÏÂÔØËٶȸü¿ì£¬²¢¹ÄÀø³ÌÐòԱд³ö¸üºÃ£¬¸üÏêϸµÄÄÚÁªÎĵµ¡£
JSMin (http://www.crockford.com/javascript/jsmin.html), developed by Douglas Crockford, remained the standard in JavaScript minification for a long time. However, as web applications kept growing in size and complexity, many felt it was time to push JavaScript minification a step further. This is the main reason behind the development of the YUI Compres ......
Working Around Caching Issues ¹ØÓÚ»º´æÎÊÌâ
Adequate cache control can really enhance the user experience, but it has a downside: when revving up your application, you want to make sure your users get the latest version of the static content. This is accomplished by renaming static resources whenever they change.
³ä·ÖÀûÓûº´æ¿ØÖÆ¿ÉÕæÕýÌá¸ßÓû§ÌåÑ飬µ«ËüÓÐÒ»¸öȱµã£ºµ±Ó¦ÓóÌÐò¸üÐÂÖ®ºó£¬ÄãÏ£ÍûÈ·±£Óû§µÃµ½¾²Ì¬ÄÚÈݵÄ×îа汾¡£Õâͨ¹ý¶Ô¸Ä¶¯µÄ¾²Ì¬×ÊÔ´½øÐÐÖØÃüÃûʵÏÖ¡£
Most often, developers add a version or a build number to filenames. Others like to append a checksum. Personally, I like to use a timestamp. This task can be automated using Ant. The following target takes care of renaming JavaScript files by appending a timestamp in the form of yyyyMMddhhmm:
´ó¶àÇé¿öÏ£¬¿ª·¢ÕßÏòÎļþÃûÖÐÌí¼ÓÒ»¸ö°æ±¾ºÅ»ò¿ª·¢±àºÅ¡£ÓÐÈËϲ»¶×·¼ÓÒ»¸öУÑéºÍ¡£¸öÈ˶øÑÔ£¬ÎÒ¸üϲ»¶Ê±¼ä´Á¡£´ËÈÎÎñ¿ÉÓÃAnt×Ô¶¯Íê³É¡£ÏÂÃæµÄÄ¿±êÌåͨ¹ý¸½¼ÓÒ»¸ö ......
µÚʮՠ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
¼ì²éͼƬ£¬Ñùʽ±í£¬ºÍ½Å±¾µÄ¼ÓÔعý³Ì£¬»ã±¨ËüÃǶÔÕû¸öÒ³ ......
Firebug
Firefox is a popular browser with developers, partially due to the Firebug addon (available at http://www.getfirebug.com/), which was developed initially by Joe Hewitt and is now maintained by the Mozilla Foundation. This tool has increased the productivity of web developers worldwide by providing insights into code that were never before possible.
¶Ô¿ª·¢ÈËÔ±À´Ëµ£¬FirefoxÊÇÒ»¸öʱ÷ÖµÄä¯ÀÀÆ÷£¬²¿·ÖÔÒòÊÇFirebug²å¼þ£¨http://www.getfirebug.com/£©ÓÉJoe HewittÊ×´´ÏÖÔÚÓÉMozilla»ù½ð»áά»¤¡£´Ë¹¤¾ß¾ßÓÐÇ°ËùδÓеĴúÂ붴²ìÁ¦£¬Ìá¸ßÁËÈ«ÊÀ½çÍøÒ³¿ª·¢ÕßµÄÉú²úÁ¦¡£
Firebug provides a console for logging output, a traversable DOM tree of the current page, style information, the ability to introspect DOM and JavaScript objects, and more. It also includes a profiler and network analyzer, which will be the focus of this section. Firebug is also highly extensible, enabling custom panels to be easily added.
FirebugÌṩÁËÒ»¸ö¿ ......
×ܼǼÊý:2244; ×ÜÒ³Êý:374; ÿҳ6 Ìõ;
Ê×Ò³ ÉÏÒ»Ò³ [1] [2] [3] [4] 5
[6] [7] [8] [9] [10] ÏÂÒ»Ò³ βҳ