精品一区二区三区在线成人,欧美精产国品一二三区,Ji大巴进入女人66h,亚洲春色在线视频

這個(gè)“低調(diào)到不行”的 Chrome 新功能,能幫你省下成片時(shí)間

系統(tǒng) 瀏覽器
Chrome 上線了 Performance Extensibility API。它讓開發(fā)者能把“自己關(guān)心的信號(hào)”直接塞進(jìn) DevTools 的 Performance 面板里可視化。我啃了好一陣官方文檔(密不透風(fēng)不夸張),現(xiàn)在把精華捋給你。

最近,Chrome 上線了 Performance Extensibility API。它讓開發(fā)者能把“自己關(guān)心的信號(hào)”直接塞進(jìn) DevTools 的 Performance 面板里可視化。我啃了好一陣官方文檔(密不透風(fēng)不夸張),現(xiàn)在把精華捋給你。

你大概也經(jīng)歷過:在無窮無盡的面板里來回橫跳,找不到關(guān)鍵線索,越看越糊涂。

掌控你的指標(biāo):把“你在乎的”搬進(jìn) Performance 面板

Performance Extensibility API 允許你在 DevTools 的 Performance 面板里自定義軌道(track)與自定義事件,等于給你的應(yīng)用做一份“專屬體檢報(bào)告”。從基礎(chǔ)開始最穩(wěn)。

先來看最小閉環(huán):在頁面里埋點(diǎn)、量時(shí)間、打印結(jié)果。

<script>performance.mark('cssStart');</script>

<linkrel="stylesheet"href="/app.css">

<script>
  performance.mark('cssEnd');
  performance.measure('cssTime', 'cssStart', 'cssEnd');
</script>

上面做了三件事:

  1. 用 performance.mark() 打點(diǎn) cssStart;
  2. 加載樣式;
  3. 再打點(diǎn) cssEnd 并用 performance.measure() 量兩點(diǎn)之間的耗時(shí)。

想快速看數(shù)據(jù)?控制臺(tái)直接取:

console.log(`CSS Start: ${performance.getEntriesByName('cssStart')[0].startTime} ms`);
console.log(`CSS Duration: ${performance.getEntriesByName('cssTime')[0].duration} ms`);

同理,JavaScript 片段也能這樣測(cè):

performance.mark('jsStart');

// 模擬一段“費(fèi)時(shí)”的 JS
setTimeout(() => {
  performance.mark('jsEnd');
  performance.measure('jsTime', 'jsStart', 'jsEnd');

  console.log(performance.getEntriesByName('jsStart')[0].startTime);
  console.log(performance.getEntriesByName('jsTime')[0].duration);
}, 1000);

為什么要進(jìn) Performance 面板?

  • console.log():輕量與即時(shí),不必全量錄制就能看到數(shù)字;
  • Performance 面板:把你的標(biāo)記與網(wǎng)絡(luò)/腳本/渲染等系統(tǒng)軌道并排對(duì)照,全景式排查更直觀。

圖片圖片

Extensibility API:不僅是打點(diǎn),更是“自定義軌道”

新 API 的關(guān)鍵點(diǎn)在于:

  • 你可以聲明自定義 Track,把事件放到屬于你的一條線上;
  • 還能為 mark/measure 添加豐富的細(xì)節(jié),在 DevTools 中直接可視化。

先開啟自定義 Track 能力:

圖片圖片

然后,給 mark 增加 DevTools 識(shí)別信息(dataType: 'marker'):

performance.mark('jsStart', {
detail: {
    devtools: {
      dataType: 'marker'
    }
  }
});

// 模擬一段“費(fèi)時(shí)”的 JS
setTimeout(() => {
  performance.mark('jsEnd', {
    detail: {
      devtools: {
        dataType: 'marker'
      }
    }
  });
  performance.measure('jsTime', 'jsStart', 'jsEnd');

console.log(performance.getEntriesByName('jsStart')[0].startTime);
console.log(performance.getEntriesByName('jsTime')[0].duration);
}, 5000);

把上面代碼貼進(jìn)瀏覽器控制臺(tái),切到 Performance,錄幾秒。

接著,把 measure 放到自定義的 Track 上:

performance.measure('jsTime', {
  start: 'jsStart',
  end: 'jsEnd',
  detail: {
    devtools: {
      track: 'JavaScript Custom Tracker - Amit'
    }
  }
});

圖片圖片

一份完整的 Demo:第三方資源、耗時(shí)細(xì)分、屬性展示,一條龍

下面這段 HTML 把 CSS 加載全過程“打點(diǎn)→量時(shí)→標(biāo)注”為一條自定義軌。保存為 .html 后用 Chrome 打開,開始錄制即可。

<!doctype html>
<htmllang="en-gb">
<metacharset="utf-8">
<metaname="viewport"content="width=device-width, minimum-scale=1.0">

<title>Extensibility API</title>

<script>
    performance.mark('cssStart', {
      detail: {
        devtools: {
          dataType: "marker",
          tooltipText: 'Get Bootstrap CSS from CDN',
          color: "secondary-light"
        }
      }
    });
  </script>

<linkrel="stylesheet">

<script>
    performance.mark('cssEnd');

    // 抓取該樣式的資源級(jí)計(jì)時(shí)信息
    const css                  = document.getElementById('jsCSS');
    const cssURL               = css.href;
    const cssTimingInformation = performance.getEntriesByName(cssURL)[0];
    const cssTransferSize      = (cssTimingInformation.transferSize    / 1024).toFixed(2);
    const cssDecodedBodySize   = (cssTimingInformation.decodedBodySize / 1024).toFixed(2);
    const cssLatencyDuration   = (cssTimingInformation.responseStart   - cssTimingInformation.startTime).toFixed(2);
    const cssdownloadDuration  = (cssTimingInformation.responseEnd     - cssTimingInformation.responseStart).toFixed(2);
  </script>

<script>
    performance.measure('cssTime', {
      start: 'cssStart',
      end:   'cssEnd',
      detail: {
        devtools: {
          dataType:    'track-entry',
          trackGroup:  'Third Party Instrumentation',
          track:       'CSS',
          tooltipText: 'CSS Downloaded and Parsed',
          color:       'secondary-light',
          properties: [
            ['URL',                  cssURL],
            ['Transferred Size',  `${cssTransferSize} KB`],
            ['Decoded Body Size', `${cssDecodedBodySize} KB`],
            ['Queuing & Latency', `${cssLatencyDuration} ms`],
            ['Download',          `${cssdownloadDuration} ms`]
          ]
        }
      }
    });
  </script>
</html>

看點(diǎn)在哪里?

  • 你不僅能看到“從請(qǐng)求到解析”的總耗時(shí),還能拆分:排隊(duì)/首包延遲、下載時(shí)長、傳輸體積、解碼體積;
  • 這些細(xì)節(jié)直接展示在自定義條目上,鼠標(biāo)懸停即可讀懂;
  • 當(dāng)它與網(wǎng)絡(luò)/主線程/渲染/JS 采樣軌并排時(shí),瓶頸會(huì)“自己跳出來”。

實(shí)操建議(真能省時(shí)間的部分)

  1. 先埋點(diǎn),后錄制:把你懷疑的路徑都放上 mark/measure,用命名來表達(dá)意圖(如 route:home→product)。
  2. 一條軌講一件事:用 detail.devtools.track 歸類,避免把所有事件堆到 Timings。
  3. 用屬性說人話:把 URL、大小、分段時(shí)長等放進(jìn) properties,減少“錄完還要再翻 Request 面板”的往返。
  4. 短錄多次:與其錄 60s 看花眼,不如錄 5–10s 聚焦一條鏈路,逐段定位。
  5. 對(duì)照回放:修一次就錄一次,延遲/抖動(dòng)/主線程阻塞是否下降,一眼即判。

總結(jié)

今天我們把 Performance Extensibility API 的核心玩法走了一遍:

  • mark/measure 打點(diǎn)量時(shí);
  • detail.devtools 把事件“搬進(jìn)”自定義軌;
  • “屬性 + 提示 + 顏色”讓復(fù)盤更高效;
  • 配合 Performance 面板的系統(tǒng)軌道,定位更快,溝通更順。

下一次你懷疑“頁面慢在某一步”,別再盲猜。埋點(diǎn)→錄制→證據(jù)說話,你會(huì)省下成片時(shí)間。

責(zé)任編輯:武曉燕 來源: 大遷世界
相關(guān)推薦

2009-09-17 09:39:28

Chrome 3.0谷歌瀏覽器

2010-04-06 09:47:38

2020-10-23 16:25:23

Chrome 86前端文件

2013-07-17 13:48:56

Chrome 29瀏覽器

2021-06-15 14:47:06

GoogleChrome標(biāo)簽組

2019-07-08 17:40:41

DBS復(fù)合機(jī)惠普

2017-02-06 15:50:21

谷歌Chrome小程序

2025-07-09 00:00:00

2021-01-11 17:50:00

Chrome 88Chrome瀏覽器

2021-04-15 05:52:06

谷歌Chrome 瀏覽器

2009-11-06 17:12:46

MacChromeDev分支

2010-10-28 16:31:10

2023-08-07 09:52:18

Edge瀏覽器

2023-07-17 07:05:43

ChatGPTOpenAI

2009-05-22 08:56:02

GoogleChrome瀏覽器

2019-11-18 09:20:36

chromebookChrome應(yīng)用Chrome

2020-06-28 08:21:07

Chrome瀏覽器Chrome瀏覽器

2021-04-19 05:55:22

谷歌Chrome 瀏覽器

2014-12-19 09:53:25

Android 5.1
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 阳西县| 惠来县| 通海县| 永州市| 林周县| 祁东县| 安丘市| 盘锦市| 岑巩县| 顺昌县| 恩施市| 天柱县| 黄大仙区| 玉溪市| 武威市| 财经| 阳高县| 邛崃市| 滕州市| 清丰县| 桦南县| 宝坻区| 井陉县| 富平县| 绵竹市| 江西省| 南皮县| 普定县| 桐庐县| 外汇| 泰州市| 若尔盖县| 德清县| 泾川县| 延庆县| 榆树市| 应城市| 青神县| 水城县| 剑阁县| 德钦县|