PerformanceResourceTiming.domainLookupEnd

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2017.

domainLookupEnd は読み取り専用プロパティで、ブラウザーがリソースのドメイン名検索を終了した直後の timestamp を返します。

ユーザーエージェントのキャッシュにドメイン情報があった場合、domainLookupStartdomainLookupEnd はユーザーエージェントがキャッシュからのドメインデータの取得を開始および終了した時刻を表します。

domainLookupEnd プロパティは、以下の値を取ります。

  • ブラウザーがリソースのドメイン名検索を完了した直後の時刻を表す DOMHighResTimeStamp
  • リソースがキャッシュから即座に取得された場合は 0 です。
  • リソースがオリジン間リクエストで取得され、HTTP の Timing-Allow-Origin レスポンスヘッダーが使用されなかった場合は 0 となります。

DNS ルックアップ時間の計測

domainLookupEnddomainLookupStart プロパティを使用すると、 DNS ルックアップの発生に対してどれだけ時間がかかるかを計測することができます。

js
const dns = entry.domainLookupEnd - entry.domainLookupStart;

PerformanceObserver を使用した例です。このオブジェクトは、新しい resource パフォーマンス項目がブラウザーのパフォーマンスタイムラインに記録されると、それを通知します。オブザーバーが作成される前の項目にアクセスするために buffered オプションを使用します。

js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    const dns = entry.domainLookupEnd - entry.domainLookupStart;
    if (dns > 0) {
      console.log(`${entry.name}: DNS lookup duration: ${dns}ms`);
    }
  });
});

observer.observe({ type: "resource", buffered: true });

Performance.getEntriesByType() を使用した例です。このメソッドを呼び出した時点でブラウザー上のパフォーマンスタイムラインに存在する resource パフォーマンス項目のみを表示します。

js
const resources = performance.getEntriesByType("resource");
resources.forEach((entry) => {
  const dns = entry.domainLookupEnd - entry.domainLookupStart;
  if (dns > 0) {
    console.log(`${entry.name}: DNS lookup duration: ${dns}ms`);
  }
});

オリジン間のタイミング情報

domainLookupEnd プロパティの値が 0 である場合、そのリソースはオリジン間リクエストである可能性があります。オリジン間のタイミング情報を見るためには、HTTP の Timing-Allow-Origin レスポンスヘッダーを設定する必要があります。

例えば、https://developer.mozilla.org にタイミングリソースを見ることを許可するには、オリジン間リソースで次のものを送信する必要があります。

http
Timing-Allow-Origin: https://developer.mozilla.org

仕様書

Specification
Resource Timing
# dom-performanceresourcetiming-domainlookupend

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
domainLookupEnd

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

関連情報