[·Òë]High Performance JavaScript(009)
µÚÈýÕ DOM Scripting DOM±à³Ì
DOM scripting is expensive, and it's a common performance bottleneck in rich web applications. This chapter discusses the areas of DOM scripting that can have a negative effect on an application's responsiveness and gives recommendations on how to improve response time. The three categories of problems discussed in the chapter include:
¶ÔDOM²Ù×÷´ú¼Û°º¹ó£¬ÔÚ¸»ÍøÒ³Ó¦ÓÃÖÐͨ³£ÊÇÒ»¸öÐÔÄÜÆ¿¾±¡£±¾ÕÂÌÖÂÛ¿ÉÄܶԳÌÐòÏìÓ¦Ôì³É¸ºÃæÓ°ÏìµÄDOM±à³Ì£¬²¢¸ø³öÌá¸ßÏìÓ¦ËٶȵĽ¨Òé¡£±¾ÕÂÌÖÂÛÈýÀàÎÊÌ⣺
• Accessing and modifying DOM elements
·ÃÎʺÍÐÞ¸ÄDOMÔªËØ
• Modifying the styles of DOM elements and causing repaints and reflows
ÐÞ¸ÄDOMÔªËØµÄÑùʽ£¬Ôì³ÉÖØ»æºÍÖØÐÂÅŰæ
• Handling user interaction through DOM events
ͨ¹ýDOMʼþ´¦ÀíÓû§ÏìÓ¦
But first—what is DOM and why is it slow?
µ«Ê×ÏÈ——ʲôÊÇDOM£¿ËûΪʲôÂý£¿
DOM in the Browser World ä¯ÀÀÆ÷ÊÀ½çÖеÄDOM
The Document Object Model (DOM) is a language-independent application interface (API) for working with XML and HTML documents. In the browser, you mostly work with HTML documents, although it's not uncommon for web applications to retrieve XML documents and use the DOM APIs to access data from those documents.
Îĵµ¶ÔÏóÄ£ÐÍ£¨DOM£©ÊÇÒ»¸ö¶ÀÁ¢ÓÚÓïÑԵģ¬Ê¹ÓÃXMLºÍHTMLÎĵµ²Ù×÷µÄÓ¦ÓóÌÐò½Ó¿Ú£¨API£©¡£ÔÚä¯ÀÀÆ÷ÖУ¬Ö÷ÒªÓëHTMLÎĵµ´ò½»µÀ£¬ÔÚÍøÒ³Ó¦ÓÃÖмìË÷XMLÎĵµÒ²ºÜ³£¼û¡£DOM APIsÖ÷ÒªÓÃÓÚ·ÃÎÊÕâЩÎĵµÖеÄÊý¾Ý¡£
Even though the DOM is a language-independent API, in the browser the interface is implemented in JavaScript. Since most of the work in client-side scripting has to do with the underlying document, DOM is an important part of everyday JavaScript coding.
¾¡¹ÜDOMÊÇÓëÓïÑÔÎ޹صÄAPI£¬ÔÚä¯ÀÀÆ÷ÖеĽӿÚÈ´ÊÇÒÔJavaScriptʵÏֵġ£¿Í»§¶Ë´ó¶àÊý½Å±¾³ÌÐòÓëÎĵµ´ò½»µÀ£¬DOM¾Í³ÉΪJavaScript´úÂëÈÕ³£ÐÐΪÖÐÖØÒªµÄ×é³É²¿·Ö¡£
 
Ïà¹ØÎĵµ£º
javascriptµÄhistory.go(-1)
echo '<script language="javascript">{alert("ÁôÑÔ²»ÄÜΪ¿Õ!");history.go(-1);}</script>';}
echo '<script language="javascript">{alert("ÁôÑÔ²»ÄÜΪ¿Õ!");return true;}</script>';}
ÕâÊDz»Ë¢ÐÂÒ³ÃæµÄ·½Ê½ ......
phpÖеÄevalºÍJavaScriptÖеÄevalÇø±ð£º
Definition and Usage
¶¨ÒåºÍÓ÷¨
The eval() function evaluates a
string as PHP code.
eval()º¯ÊýµÄ×÷ÓÃÊÇ£º·µ»ØÓëPHP´úÂëÏà¶ÔÓ¦µÄ×Ö·û´®¡£
The string
must be valid PHP code and must end with semicolon.
Õâ¸ö×Ö·û´®±ØÐëÊÇÓÐЧµÄPHP´úÂ룬
²¢ÇÒ±ØÐëÒԷֺŽáÊø¡ ......
// µ÷ÓÃÒ³ÃæµÄˢз½·¨
IHTMLWindow2* pWindow;
IHTMLDocument2* pDocument;
HRESULT hr = GetDHtmlDocument(&pDocument);
hr = pDocument->get_pa ......
**
* ÎÒÔÚÍøÉÏ¿´µ½¹ýºÜ¶àBASE64µÄJavaScriptËã·¨£¬¶¼¾õµÃ²»ÂúÒ⣬ÓÚÊÇ×Ô¼ºÐ´ÁËÒ»¸ö£¬ÔÚÕâÀï·ÖÏíһϡ£
* ÎҵĴúÂëÔÚÖÊÁ¿µÄЧÂʶ¼½Ï¸ß£¬Ã»ÓÐһЩÈßÓàµÄ²Ù×÷¡£×ÜÌåÀ´½²ÎÒ¾õµÃ·Ç³£²»´í¡£
* Èç¹û´ó¼ÒÓÐʲô²»¶®µÄµØ·½¿ÉÒÔÎÊÎÒ¡£
*/
var BASE64={
/**
* ´Ë±äÁ¿Îª±àÂëµÄ ......
¹¦ÄÜ£º
ÖØÐ¼ÓÔØÎĵµ¡£
Óï·¨£º
location.reload(force)
²ÎÊý£º
force£º¿ÉÑ¡²ÎÊý£¬ÊÇÒ»¸ö²¼¶ûÖµ¡£
Èç¹ûÊ¡ÂÔ²ÎÊý£¬»òÕß²ÎÊýÊÇfalse£¬Ëü¾Í»áÓÃHTTPÍ·If-Modified-SinceÀ´¼ì²â·þÎñÆ÷ÉϵÄÎĵµÊÇ·ñÒѸı䡣Èç¹ûÎĵµÒѸÄ
±ä£¬reload()»áÔÙ´ÎÏÂÔØ¸ÃÎĵµ¡£Èç¹ûÎĵµÎ´¸Ä±ä£¬Ôò¸Ã·½·¨½«´Ó»º´æÖÐ ......