Early Hints を使うと、オリジンサーバーがレスポンス全体を組み立てているあいだに、ブラウザーがリソースの読み込みを始められます。エンドユーザー向けのページ読み込みが速くなります。SaaS プロバイダーとして、一部のカスタムホスト名では速度を優先したいことがあります。カスタムメタデータを使うと、カスタムホスト名ごとに Early Hints を有効化 できます。
SaaS 向け Early Hints を使う前に、カスタムホスト名を作成する必要があります。まだの場合は Cloudflare for SaaS のスタートガイド を確認してください。
-
Cloudflare ダッシュボードで ゾーン ID を確認 します。
-
API Tokens ↗ ページの Global API Key で Authentication Key を確認します。
-
新しいカスタムホスト名を作成する 場合は、次の例のように
"early_hints": "on"を指定して API を呼び出します。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"hostname": "<CUSTOM_HOSTNAME>",
"ssl": {
"method": "http",
"type": "dv",
"settings": {
"http2": "on",
"min_tls_version": "1.2",
"tls_1_3": "on",
"early_hints": "on"
},
"bundle_method": "ubiquitous",
"wildcard": false
}
}'- 既存のカスタムホスト名の場合は、
GET呼び出しでそのホスト名のidを確認します。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates WriteSSL and Certificates Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames?hostname=%7Bhostname%7D" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"- 次の例のように、
"early_hints": "on"を指定して API を呼び出します。
Required API token permissions
At least one of the following token permissions is required:SSL and Certificates Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/custom_hostnames/$CUSTOM_HOSTNAME_ID" \
--request PATCH \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"ssl": {
"method": "http",
"type": "dv",
"settings": {
"http2": "on",
"min_tls_version": "1.2",
"tls_1_3": "on",
"early_hints": "on"
}
}
}'現時点では、settings 内のすべてのオプションを指定する必要があります。含めないとデフォルト値に戻るためです。Early Hints を更新する前に、ホスト名の id を返す出力を使って、現在の設定を取得できます。