Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

[·­Òë]High Performance JavaScript(024)

Data Format Conclusions  Êý¾Ý¸ñʽ×ܽá
    Favor lightweight formats in general; the best are JSON and a character-delimited custom format. If the data set is large and parse time becomes an issue, use one of these two techniques:
    ×ܵÄÀ´ËµÔ½ÇáÁ¿¼¶µÄ¸ñʽԽºÃ£¬×îºÃÊÇJSONºÍ×Ö·û·Ö¸ôµÄ×Ô¶¨Òå¸ñʽ¡£Èç¹ûÊý¾Ý¼¯ºÜ´ó»òÕß½âÎöʱ¼ä³ÉÎÊÌ⣬ÄÇô¾ÍʹÓÃÕâÁ½ÖÖ¸ñʽ֮һ£º
• JSON-P data, fetched using dynamic script tag insertion. This treats the data as executable JavaScript, not a string, and allows for extremely fast parsing. This can be used across domains, but shouldn't be used with sensitive data.
  JSON-PÊý¾Ý£¬Óö¯Ì¬½Å±¾±êÇ©²åÈë·¨»ñÈ¡¡£Ëü½«Êý¾ÝÊÓΪ¿ÉÔËÐеÄJavaScript¶ø²»ÊÇ×Ö·û´®£¬½âÎöËٶȼ«¿ì¡£ËüÄܹ»¿çÓòʹÓ㬵«²»Ó¦Éæ¼°Ãô¸ÐÊý¾Ý¡£
• A character-delimited custom format, fetched using either XHR or dynamic script tag insertion and parsed using split(). This technique parses extremely large datasets slightly faster than the JSON-P technique, and generally has a smaller file size.
  ×Ö·û·Ö¸ôµÄ×Ô¶¨Òå¸ñʽ£¬Ê¹ÓÃXHR»ò¶¯Ì¬½Å±¾±êÇ©²åÈë¼¼ÊõÌáÈ¡£¬Ê¹ÓÃsplit()½âÎö¡£´Ë¼¼ÊõÔÚ½âÎö·Ç³£´óÊý¾Ý¼¯Ê±±ÈJSON-P¼¼ÊõÂԿ죬¶øÇÒͨ³£Îļþ³ß´ç¸üС¡£
    The following table and Figure 7-1 show all of the performance numbers again (in order from slowest to fastest), so that you can compare each of the formats in one place. HTML is excluded, since it isn't directly comparable to the other formats.
    ϱíºÍͼ7-1ÔÙ´ÎÏÔʾÁËËùÓз½·¨µÄÐÔÄÜÊý¾Ý£¨°´ÕÕ´ÓÂýµ½¿ìµÄ˳Ðò£©£¬Äã¿ÉÒÔÔڴ˱ȽÏÿÖÖ¸ñʽµÄÓÅÁÓ¡£HTMLδ°üÀ¨£¬ÒòΪËüÓëÆäËû¸ñʽ²»ÄÜÖ±½Ó±È½Ï¡£
Figure 7-1. A comparison of data format download and parse times
ͼ7-1  ¸÷ÖÖÊý¾Ý¸ñʽÏÂÔØºÍ½âÎöµÄʱ¼ä
    Keep in mind that these numbers are from a single test run in a single browser. The results should be used as general indicators of performance, not as hard numbers. You can run these tests yourself at http://techfoolery.com/formats/.
    Çë×¢Ò⣬ÕâЩÊ


Ïà¹ØÎĵµ£º

javaScript¹Ø±Õä¯ÀÀÆ÷ (²»µ¯³öÌáʾ¿ò)

£¼script language="javaScript"£¾
function closeWindow()
{
¡¡window.opener = null;
¡¡window.open(' ', '_self', ' ');
¡¡window.close();
}
£¼/script£¾
£¼input type='button' value='¹Ø±Õ´°¿Ú' onClick="closeWindow()"£¾
»ò
£¼input type="button" value="¹ ......

[·­Òë]High Performance JavaScript(012)

µÚËÄÕ  Algorithms and Flow Control  Ëã·¨ºÍÁ÷³Ì¿ØÖÆ
    The overall structure of your code is one of the main determinants as to how fast it will execute. Having a very small amount of code doesn't necessarily mean that it will run quickly, and having a large amount of code ......

[·­Òë]High Performance JavaScript(014)

Recursion Patterns  µÝ¹éģʽ
    When you run into a call stack size limit, your first step should be to identify any instances of recursion in the code. To that end, there are two recursive patterns to be aware of. The first is the straightforward recursive pattern represented ......

[·­Òë]High Performance JavaScript(019)

µÚÁùÕ  Responsive Interfaces  ÏìÓ¦½Ó¿Ú
    There's nothing more frustrating than clicking something on a web page and having nothing happen. This problem goes back to the origin of transactional web applications and resulted in the now-ubiquitous "please click only once" m ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ