久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      讓web app更快的HTML5最佳實(shí)踐


       簡介

        本文重點(diǎn)關(guān)注如何充分利用HTML5和CSS讓web app運(yùn)行更加流暢.

      讓web app更快的HTML5最佳實(shí)踐

       Tip 1: 使用web storage代替cookie

        cookie最大的缺陷是在每一次HTTP請求中都會(huì)攜帶所有符合規(guī)則的cookie數(shù)據(jù).這會(huì)增加請求響應(yīng)時(shí)間,特別是XHR請求. 在HTML5中使用sessionStorage和localStorage代替cookie是更好的做法.

        這另種方法可以將數(shù)據(jù)永久或者以session時(shí)間存儲(chǔ)在用戶本地.數(shù)據(jù)不會(huì)隨著HTTP請求傳遞.所以我們優(yōu)先使用web storage,僅僅使用cookie作為替代方案.

      // if localStorage is present, use that  if (('localStorage' in window) && window.localStorage !== null) {      // easy object property API    localStorage.wishlist = '["unicorn", "Narwhal", "deathbear"]';    } else {      // without sessionStorage we'll have to use a far-future cookie    // with document.cookie's awkward API    var date = new Date();    date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));    var expires = date.toGMTString();    var cookiestr = 'wishlist=["unicorn", "Narwhal", "deathbear"];' +                    ' expires=' + expires + '; path=/';    document.cookie = cookiestr;  }

       Tip 2: 使用CSS Transition代替JavaScript動(dòng)畫

        CSS Transition能帶來更高的性能,更少的代碼,更容易維護(hù)和理解.

       Tip 3: 使用客戶端數(shù)據(jù)庫代替服務(wù)器請求

        Web SQL Database和IndexedDB讓瀏覽器有了數(shù)據(jù)庫存儲(chǔ)能力.很多應(yīng)用場景可以遷移到客戶端數(shù)據(jù)庫以減少服務(wù)器的請求次數(shù).

        localStorage和sessionStorage在簡單數(shù)據(jù)存儲(chǔ)時(shí)比客戶端數(shù)據(jù)庫更快,可以用來實(shí)現(xiàn)一些簡單的狀態(tài),進(jìn)度保存.

        當(dāng)一個(gè)組件需要管理上百條數(shù)據(jù)(如好友列表),同時(shí)支持用戶搜索, 過濾, 排序時(shí), 客戶端數(shù)據(jù)庫存儲(chǔ)一份數(shù)據(jù)可以有效減少HTTP請求次數(shù). 查看Web SQL Database tutorial獲取詳細(xì)指導(dǎo).

       Tip 4: 使用JavaScript原生API

        隨著更高版本JavaScript的普及, 像Array prototype新增了很多API都可以在大多數(shù)瀏覽器中直接使用.例如:

      // give me a new array of all values multiplied by 10  [5, 6, 7, 8, 900].map(function (value) {    return value * 10;  });  // [50, 60, 70, 80, 9000]    // create links to specs and drop them into #links.  var linksList = document.querySelector('#links');  var links = [];  ['html5', 'css3', 'webgl'].forEach(function (value) {      links.push(value.link('http://google.com/search?btnI=1&q=' + value + ' spec'));  });  linksList.innerHTML = links.join('');    // return a new array of all mathematical constants under 2  [3.14, 2.718, 1.618].filter(function (number) {    return number < 2;  });    // you can also use these extras on other collections link nodeLists  [].forEach.call(document.querySelectorAll('section[data-bucket]'),    function (elem, i) {      localStorage['bucket' + i] = elem.getAttribute('data-bucket');  });

        通常情況下這些原生方法比手動(dòng)編寫循環(huán)要快:

      for (var i = 0, len = arr.length; i < len; ++i) {  }

        使用原生JSON.parse()比json2.js更加高效,安全.

        原生的String.prototype.trim也是一個(gè)很好的例子, 這些功能不是HTML5中的,也應(yīng)該得到廣泛的應(yīng)用.

       Tip 5: 不僅僅為離線app使用cache manifest,在線網(wǎng)站網(wǎng)站也可以適當(dāng)使用

        后臺(tái)管理系統(tǒng)這樣的站點(diǎn)使用緩存可以極大提高性能.

        cache manifest比設(shè)置Expires有一些優(yōu)勢:明確地聲明需要緩存的文件,瀏覽器可以進(jìn)行優(yōu)化,可能在你使用之前就已經(jīng)提前下載到本地了.

        可以將頁面基本結(jié)構(gòu)看做模板, 顯示的內(nèi)容隨著數(shù)據(jù)變化, 將可模板化的HTML結(jié)構(gòu)通過cache.manifest進(jìn)行緩存, 從服務(wù)器端獲取JSON數(shù)據(jù)之后更新內(nèi)容.

        查看application cache tutorial獲取詳細(xì)指導(dǎo).

       Tip 6: enable硬件加速來增強(qiáng)視覺體驗(yàn)

        某些瀏覽器可能使用GPU加速讓高速動(dòng)畫更加平滑.Firefox Minefield, IE9, Safari已經(jīng)宣稱實(shí)現(xiàn)了硬件加速. Chromium也增加了window平臺(tái)的3D transform加速.各個(gè)瀏覽器對硬件加速的支持肯定會(huì)越來越好.

        在支持并啟動(dòng)了硬件加速的情況下, 動(dòng)畫, rotation, scaling, opacity肯定會(huì)更加平滑. 所有實(shí)際操作都發(fā)生在GPU而不需要內(nèi)容的重繪. 然而需要注意的是,任何影響頁面布局的操作都會(huì)降低速度.

       Tip 7: 使用web worker執(zhí)行需要大量CPU資源的操作

        web worker有兩個(gè)好處: 1) 快速 2) 不阻塞瀏覽器響應(yīng). 點(diǎn)擊web worker slide查看更多信息.

        web worker的一些可能的使用場景:

      • 長文本格式化

      • 語法高亮

      • 圖片處理

      • 圖片合成

      • 大數(shù)組處理

       Tip 8: HTML5 表單屬性和input類型

        HTML5增加了一系列input type,包括search, tel, url, email, datetime, date, month, week, time, number, range, color等. 在支持這些功能的瀏覽器中使用原生功能, js插件作為補(bǔ)充.

        像placeholder, required, pattern都能極大提高頁面的可用性,和性能.

         點(diǎn)擊HTML5 form 資料查看更多信息.

       Tip 9: 使用CSS3減少圖片的使用

        減少圖片能減少HTTP請求,同時(shí)減少頁面大小,更容易維護(hù),常用的屬性如下:

      • linear and radial gradients

      • border-radius

      • box-shadow

      • rgba

      • transform

      • css mask

        常見的使用場景有: polished buttons via gradients, replicate many other effects

       Tip 10: 使用WebSocket代替XHR提供更快交互和更少的帶寬

        WebSockets是為了Comet而設(shè)計(jì)的. 使用它實(shí)現(xiàn)Comet比XHR確實(shí)帶來更多的好處.

        原文鏈接: http://www.html5rocks.com/en/tutorials/speed/quick/

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)