ÎÒÃÇͨ¹ýÕýÔò½« js ºÍ css ±êÇ©²¿·ÖÈ¡³ö£º
extractCode: function(str, isStyle) { var cata = isStyle ? "style" : "script" , scriptFragment = "<" + cata + "[^>]*>([\\S\\s]*?)</" + cata + "\\s*>" , matchAll = new RegExp(scriptFragment, "img") , matchOne = new RegExp(scriptFragment, "im") , matchResults = str.match(matchAll) || [] , ret = []; for (var i = 0, len = matchResults.length; i < len; i++) { var temp = (matchResults[i].match(matchOne) || [ "", "" ])[1]; temp && ret.push(temp); } return ret; }³É¹¦µØ½« script ÒÔ¼° style ±êÇ©ÄÚµÄÄÚÈÝÌáÈ¡Á˳öÀ´£¬ÇÉÃîµØÓÃÁËÕýÔòÖеÄ×Ó±í´ïʽ¡£
evalScripts/evalStyles½Å±¾Ö´ÐУ¬ÑùʽäÖȾ¡£
evalScripts: function(code) { var head = doc.getElementsByTagName("head")[0] , js = doc.createElement("script"); js.text = code; head.insertBefore(js, head.firstChild); head.removeChild(js); }, evalStyles: function(code) { var head = doc.getElementsByTagName("head")[0] , css = doc.createElement("style"); css.type = "text/css"; try { css.appendChild(doc.createTextNode(code)); } catch (e) { css.styleSheet.cssText = code; } head.appendChild(css); } ÓÅȱµã & ÊÊÓó¡¾°¼òµ¥½²½² BigRender ÓÅ»¯µÄÓÅȱµã£¬ÒÔ¼°ÊÊÓó¡¾°¡£
ÓŵãºÜÃ÷ÏÔ£¬ÒòΪ¼õÉÙÁËÊ×ÆÁ DOM µÄäÖȾ£¬ËùÒÔÄܼӿìÊ×ÆÁ¼ÓÔصÄËٶȣ¬²¢ÇÒÄÜ·Ö¿é¼ÓÔØ js/css£¬·Ç³£ÊÊÓÃÓÚһЩģ¿éÇø·Ö¶ÈºÜ¸ßµÄÍøÕ¾£¨¸öÈ˾õµÃ´óÐÍÍøÕ¾µÄÄ£¿éÇø·Ö¶ÈÆÕ±éÔ½À´Ô½¸ßÁË£©¡£
ȱµãÊÇÐèÒª¸ü¸Ä DOM ½á¹¹£¨DOM ½ÚµãµÄÌæ»»ºÍäÖȾ£©£¬¿ÉÄÜ»áÒýÆðһЩÖØÅźÍÖػ档һЩûÓпªÆô js ¹¦ÄܵÄÓû§½«¿´²»µ½ÑÓ³Ù¼ÓÔصÄÄÚÈÝ£¨¿ÉÒÔÓà noscript ±êÇ©¸ø³öÒ»¸öÉÆÒâÌáÐÑ£©¡£×î´óµÄȱµã¿ÉÄÜÊDz»ÀûÓÚ SEO£¬Ò»Ð©ÒÀÀµÓÚ SEO µÄÍøÕ¾¿ÉÄÜÐèÒªÔÚ SEO ÉÏϵ㹦·òÁË£¬±ÈÈçÃÀÍÅ¡£
¹ØÓÚ SEO£¬¿ÉÒÔ¿´Ï Õâ¸öÍøÕ¾£¬ÄÜÄ£ÄâËÑË÷ÒýÇæÖ©Öë¶ÔÍøÕ¾µÄÅÀÈ¡Çé¿ö¡£ÃÀÍŶÔÓÚ BigRender ÒÔ¼° SEO ½â¾ö·½°¸ [ÃÀÍÅÍø°¸Àý]¸ÄÉÆBigRender¼¼Êõµ¼ÖµÄSEOÎÊÌâ
bigrender ͨ¹ý¼õÉÙ DOM ½Úµã£¬¼Ó¿ìÊ×ÆÁµÄäÖȾ£¬µ«ÊÇ£¬ËüÒ²ÊÇÓжîÍâµÄÐÔÄÜËðºÄµÄ£¬äÖȾǰtextarea ÀïÃæµÄ html ´úÂ룬ÔÚ·þÎñ¶Ë°Ñ html ´úÂë±£´æÔÚÒþ²ØµÄ textarea ÀïÃ棬ËùÒÔÔÚ·þÎñ¶Ë»á°Ñ html ´úÂëתÒ壺¼âÀ¨ºÅµÈ¶¼±»×ªÒåÁË£¬Õâ¸ö»áÔö¼Ó·þÎñÆ÷µÄѹÁ¦£»¶øÇÒ£¬Õâ¸ö¸ÄÔìÖ»ÊÇÇ°¶ËµÄäÖȾ£¬·þÎñÆ÷ÒÀ¾ÉÊÇÒ»´Î¼ÆËãËùÓеÄÊý¾Ý£¬Êä³öËùÓеÄÊý¾Ý£¬ÕâÒ»µãûÓеõ½Ìá¸ß¡£
Ò»°ãÀ´Ëµ£¬Ê¹Óö¼ÊǺó¶ËÆ´½Ó³É html ×Ö·û´®£¬È»ºóÈûÈë textarea ±êÇ©ÖУ¬Í¸øÇ°¶Ë¡£
demoÈç¹ûÒª×öÒ»¸öÍêÕûµÄ BigRender demo£¬¿ÉÄܱȽϸ´ÔÓ£¬»¹ÒªÉæ¼°µ½ºó¶Ë¡£
֮ǰѧϰ lazyload ʱ×ö¹ýÒ»¸öͼƬµÄÑÓ³Ù¼ÓÔØ demo£¬see ¡£ÒòΪ BigRender ÊÇ lazyload µÄ¼ÓÇ¿°æ£¬ËùÒÔ¼òµ¥µØ×öÁ˸ö BigRender °æ±¾µÄͼƬÑÓ³Ù¼ÓÔØ £¬ÊµÏֵľßÌå´úÂë¿ÉÒÔ check bigrender.js¡£Çó star£¬Çó fork~
ÆäËû³ýÁËÊ×Ò³²¿·ÖÓÃÁË textarea ×ö BigRender ÓÅ»¯Í⣬ÃÀÍÅ»¹Óõ½ÁË script ±êÇ©×öÓÅ»¯¡£±ÈÈç Õâ¸öÉÌÆ·ÏêÇéÒ³
¸ø script ±êÇ©ÉèÖøö·Ç "text/javascript" µÄ type£¬¿ÉÒÔÏÂÔØÕâ¶Î js£¬µ«²»Ö´ÐУ¬ÕâÖÖ×ö·¨ËÆÔøÏàʶ£¬ÔÚ labjs Öп´µ½¹ý¡£
¸ü¶à¿ÉÒԲο¼ Ç°¶ËÓÅ»¯ÈýÐø£ºÓÃscript´æ·Åhtml´úÂëÀ´¼õÉÙDOM½ÚµãÊý
Read Moreposted on
¡¡