Found that a lot of sites in the place Baidu share code, simply put the share code to the fixed page location on the finished, this is a very lethal way. Because, I often open a Web page, found in the Web page load to share code, sometimes spend a few seconds to request the Baidu server, the last Show Sharing button.
In fact, like this on the Web page is not very important function, we can use JS to delay loading, so as to improve the main content of the page quickly load display.
Here to share the way I put it.
A, copy Baidu share code, as follows:
Copy Code code as follows:
<!--Baidu Button BEGIN-->
<div id= "Bdshare" class= "bdshare_t bds_tools_32 get-codes-bdshare" >
<a class= "Bds_tsina" ></a>
<a class= "Bds_qzone" ></a>
<a class= "BDS_TQQ" ></a>
<a class= "Bds_renren" ></a>
<a class= "Bds_douban" ></a>
<span class= "Bds_more" ></span>
<a class= "Sharecount" ></a>
</div>
<script type= "Text/javascript" id= "Bdshare_js" Data= "type=tools&uid=0" ></script>
<script type= "Text/javascript" id= "Bdshell_js" ></script>
<script type= "Text/javascript" >
document.getElementById ("Bdshell_js"). src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil (new Date ()/3600000)
</script>
<!--Baidu Button end-->
Second, place the code
careful analysis of the above sharing code, we can find that there are 3 JS script tags, these are likely to affect the speed of the Web page rendering, and finally found that, in fact, only the last <script> tag role is to request Baidu Server, display share pictures and links. So, this JS we can put to the last load.
Here is a demo I made:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html>
<head>
<title>js Delay load Baidu Share code, improve page speed </title>
<meta http-equiv= "Content-type" content= text/html;charset=gb2312 "/>"
<style type= "Text/css" >
body{margin:0px;padding:0px;font-size:12px;}
#copyright {clear:both;}
</style>
</head>
<body>
<div id= "Baidu-share" >
<!--Baidu Button BEGIN-->
<div id= "Bdshare" class= "bdshare_t bds_tools_32 get-codes-bdshare" >
<a class= "Bds_tsina" ></a>
<a class= "Bds_qzone" ></a>
<a class= "BDS_TQQ" ></a>
<a class= "Bds_renren" ></a>
<a class= "Bds_douban" ></a>
<span class= "Bds_more" ></span>
<a class= "Sharecount" ></a>
</div>
<script type= "Text/javascript" id= "Bdshare_js" Data= "type=tools&uid=0" ></script>
<script type= "Text/javascript" id= "Bdshell_js" ></script>
<!--Baidu Button end-->
</div>
<div id= "Copyright" >
<a href= "Http://codejia.net" > Programming book PDF Download "codejia.net" </a>
</div>
<script type= "Text/javascript" >
window.onload = Sharecode;
function Sharecode () {
document.getElementById ("Bdshell_js"). src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil (new Date ()/3600000);
}
</script>
</body>
</html>
Analysis: by using the demo above, I can find that I simply put the last script tag with SRC attribute to the last dynamic load, and is loaded after the window.onload. Previously loaded with pure HTML tag code, and will not have much impact on the speed of the Web page.
Baidu Share code through this adjustment even if Baidu's server hangs, will not affect their own web page normal display.
In fact, there are plenty of places to use this technique. Want to site statistics code, Baidu Google search code, third-party advertising code, etc., we can put to the bottom of the page to load the final, so even if the third party server downtime, our own machine will not be affected much.