百度,淘寶,騰訊三大巨頭HTML頁面規範分解

【兼容html5方案】
百度貼吧,百度圖片的實現
  1. <!--[if lt IE 9]>
  2. <script>
  3. (function(){
  4.     var tags = ['header','footer','figure','figcaption','details','summary','hgroup','nav','aside','article','section','mark','abbr','meter','output','progress','time','video','audio','canvas','dialog'];
  5.     for(var i=tags.length - 1;i>-1;i--){ document.createElement(tags[i]);}
  6. })();
  7. </script>
  8. <![endif]-->
  9. <style>
  10. header,footer,section,article,aside,nav,figure{display:block;margin:0;padding:0;border:0;}
  11. </style>
複製代碼



騰訊isux研究院的實現
  1. <!--[if lt IE 9]>
  2. <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  3. <![endif]-->
複製代碼


淘寶- 我的淘寶頁實現同上,只不過是不同版本
  1. <!-- [if lt IE 9]>
  2. <script src="http://g.tbcdn.cn//tb/mytaobao/12.12.15/common/??html5shiv-min.js"></script>
  3. <![endif]-->
複製代碼


不得不提的一個插件 https://github.com/aFarkas/html5shiv 在github 上達到了3453 星的高度,獲得了國內外的廣泛認可,如果你厭煩了滿頁面的div 想盡早擁抱html5 元素,就使用它吧。

【兼容模式的選擇】
關於兼容模式
百度首頁使用的是
  1. <meta http-equiv=X-UA-Compatible content=IE=EmulateIE7>
複製代碼



百度搜索頁使用的是
  1. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
複製代碼



百度圖片,騰訊isux研究院,淘寶收藏頁使用的是
  1. <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
複製代碼



X-UA-Compatible 這是個是IE8的專用標記,用來指定IE8瀏覽器去模擬某個特定版本的IE瀏覽器的渲染方式 
chrome=1寫法可以達到的效果是如果安裝了GCF,則使用GCF來渲染頁面,如果未安裝GCF,則使用最高版本的IE內核進行渲染。

百度首頁那麼點東西他當然不在乎用哪種模式,更多地去照顧老式瀏覽器; 搜索頁傾向於速度有GCF的時候更願意使用chorme渲染。

不得不吐槽,國內各的銀行支付時的兼容支持,由此第三種得到大家的共同認可似乎也無可厚非。


【移動至上】

騰訊isux研究院的實現
  1. <!-- Mobile Specific Metas
  2. ================================================== -->
  3. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
複製代碼


淘寶主頁的實現
  1. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  2. <meta content="yes" name="apple-mobile-web-app-capable" />
複製代碼



這裏沒貼百度的,不代表百度不重視這一塊,反而太重視了,19億$買了91無線 再加上 百度App 貼吧App 音樂App 圖片APP ... 全有了。

【建議升級】

  1. <!--[if lt IE 8]>
  2. <div class="g_tips">
  3.     <p>已經有超過90%的用戶使用更高版本 <a target="_blank" title="下載Chrome" href="http://www.google.com/chrome/">Google Chrome</a> 或 <a target="_blank" href="http://www.microsoft.com/zh-cn/download/ie.aspx?q=internet+explorer">Internet Explorer</a> 體驗到了更精彩的頁面,你還不試試?</p>
  4. </div>
  5. <![endif]-->
  6. <style>
  7. .g_tips{background:#FFF691;color:#010101;text-align:center;height:40px;line-height:40px;font-family:'STHeiti','\5fae\8f6f\96c5\9ed1'}.g_tips a{color:#676767;padding:0 2px;zoom:1}
  8. </style>
複製代碼


什麼,連ie8都不是? 無法容忍啊,建議你早點換吧! 

【參考模版】
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>頁面名稱</title>
  6.     <meta name="keywords" content=""/>
  7.     <meta name="description" content=""/>
  8.     <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9.     <!-- Mobile Specific Metas
  10.     ================================================== -->
  11.     <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=no">
  12.     <meta name="apple-mobile-web-app-capable" content="yes" />
  13.     <!-- CSS
  14.     ================================================== -->
  15.     <link rel="shortcut icon" href="http://www.yunos.com/favicon.ico">
  16.     <link rel="stylesheet" href="http://m.alicdn.com/css/index.css"/>
  17.     <style>/* css */</style>
  18. </head>

  19. <body>
  20.     <!--[if lt IE 8]>
  21.     <div class="g_tips">
  22.         <p>
  23.             已經有超過90%的用戶使用更高版本
  24.             <a target="_blank" title="下載Chrome" href="http://www.google.com/chrome/">Google Chrome</a>
  25.             或
  26.             <a target="_blank" href="http://www.microsoft.com/zh-cn/download/ie.aspx?q=internet+explorer">Internet Explorer</a>
  27.             體驗到了更流暢更精彩的頁面,你還不試試?
  28.         </p>
  29.     </div>
  30.     <![endif]-->

  31.     <h1>300,000,00</h1>

  32.     <script src="js/index.js"></script>
  33.     <script>// js
  34.   </script>
  35. </body>
  36. </html>
複製代碼

<html lang="zh-CN"> 性屬說明這個html內容是以中文爲顯示和閱讀基礎,多語言的網站建議添加。
通常情況下CSS放文檔開始,腳本放在文檔末尾我想不用解釋太多
如果一個頁面足夠簡單,寫在頁面上是完全 OK 的,特別是一些簡單的專題,但是項目上需謹慎使用

頁面全局變量命名隨記 PDC FP PageInfo window.g_config (function(){window.PDC={}})(); 


【CDN加速】【dataUrl】【css spirte】【按需加載和loader機制】【壓縮檢查發佈】
作爲一個前端開發,這些你做了嗎?
發佈了12 篇原創文章 · 獲贊 8 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章