Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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»ù´¡ÖªÊ¶3

Òþ²Ø³ÉÔ±±äÁ¿
ÔÚº¯ÊýÌåÄÚ¶¨ÒåµÄ±äÁ¿Îª¾Ö²¿±äÁ¿£¬À뿪º¯Êý¾Í¹ÒµôÁË
ÔÚº¯ÊýÌåÄÚʹÓÃthis.³ÉÔ±±äÁ¿Ãû£¬ÔòΪwindow¶ÔÏ󼶱äÁ¿£¬¼´È«¾Ö±äÁ¿
¹ÊÐèÒªÕâÑùÒþ²Ø³ÉÔ±±äÁ¿£¬ÏòÍâÖ»±©Â¶get¡¢setº¯Êý
function testClass(name){
var _firstname=name;
return {
getname : function() {
return _fir ......

javascript¶¯Ì¬×°ÈëXMLÊý¾Ý


ʹÓÃjavascript´´½¨Microsoft XML DOM,¾Í¿ÉÒÔÍê³ÉÕâÒ»¹¤×÷.
// ×°ÈëÊý¾Ý.
var source = new ActiveXObject("Microsoft.XMLDOM");
source.async = false
source.load("history.xml");
// ×°ÈëÑùʽ±í.
var stylesheet = new ActiveXObject("Microsoft.XMLDOM");
stylesheet.async = false
stylesheet.load( ......

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

Regular Expression Optimization  ÕýÔò±í´ïʽÓÅ»¯
    Incautiously crafted regexes can be a major performance bottleneck (the upcoming section, "Runaway Backtracking" on page 91, contains several examples showing how severe this can be), but there is a lot you can do to improve re ......

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

µÚÆßÕ  Ajax  Òì²½JavaScriptºÍXML
    Ajax is a cornerstone of high-performance JavaScript. It can be used to make a page load faster by delaying the download of large resources. It can prevent page loads altogether by allowing for data to be transferred between the client ......

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

Data Formats  Êý¾Ý¸ñʽ
    When considering data transmission techniques, you must take into account several factors: feature set, compatibility, performance, and direction (to or from the server). When considering data formats, the only scale you need for comparison is speed.
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ