PerformanceResourceTiming.connectStart
        
        
          
                Baseline
                
                  Widely available
                
                
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年9月.
connectStart は読み取り専用プロパティで、リソースを取得するためにユーザーエージェントがサーバーへの接続の確立を開始する直前の timestamp を返します。
値
connectStart プロパティは以下の値を取ります。
- ブラウザーがリソースを取得するためにサーバーとのコネクションを確立し始める直前の 
DOMHighResTimeStamp。 - リソースがキャッシュから即座に取得された場合は 
0です。 - リソースがオリジン間リクエストで取得され、HTTP の 
Timing-Allow-Originレスポンスヘッダーが使用されなかった場合は0となります。 
例
>TCP ハンドシェイク時間の計測
connectStart と connectEnd プロパティを使用して、 TCP ハンドシェイクが発生したときにどれくらいかかるかを計測することができます。
const tcp = entry.connectEnd - entry.connectStart;
PerformanceObserver を使用した例です。このオブジェクトは、新しい resource パフォーマンス項目がブラウザーのパフォーマンスタイムラインに記録されると、それを通知します。オブザーバーが作成される前の項目にアクセスするために buffered オプションを使用します。
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    const tcp = entry.connectEnd - entry.connectStart;
    if (tcp > 0) {
      console.log(`${entry.name}: TCP handshake duration: ${tcp}ms`);
    }
  });
});
observer.observe({ type: "resource", buffered: true });
Performance.getEntriesByType() を使用した例です。このメソッドを呼び出した時点でブラウザー上のパフォーマンスタイムラインに存在する resource パフォーマンス項目のみを表示します。
const resources = performance.getEntriesByType("resource");
resources.forEach((entry) => {
  const tcp = entry.connectEnd - entry.connectStart;
  if (tcp > 0) {
    console.log(`${entry.name}: TCP handshake duration: ${tcp}ms`);
  }
});
オリジン間のタイミング情報
connectStart プロパティの値が 0 である場合、そのリソースはオリジン間リクエストである可能性があります。オリジン間のタイミング情報を見るためには、HTTP の Timing-Allow-Origin レスポンスヘッダーを設定する必要があります。
例えば、https://developer.mozilla.org にタイミングリソースを見ることを許可するには、オリジン間リソースで次のものを送信する必要があります。
Timing-Allow-Origin: https://developer.mozilla.org
仕様書
| Specification | 
|---|
| Resource Timing> # dom-performanceresourcetiming-connectstart>  | 
            
ブラウザーの互換性
Loading…