valid-speculation-rules
<script type="speculationrules"> 要素の本文を、HTML Living Standard § 7.6 Speculation rules に従って検証します(元は WICG nav-speculation ドラフトで、現在は HTML Standard へリダイレクトされます)。type 属性は ASCII 大文字小文字を区別せずに照合します(ユーザーエージェントの MIME タイプ判定に整合)。
旧script-contentルールから、type="importmap"を担うvalid-importmapとともに分割されました。
インラインの投機ルールに対して以下を違反として報告します。
- 要素本文が空・空白のみ、または JSON としてパースできない
- トップレベル値が JSON オブジェクトではない、または
prefetch/prerenderプロパティが存在しない - トップレベルに
tag/prefetch/prerender以外のキーが存在する prefetch/prerenderの値が JSON 配列ではない、またはその中のルールが JSON オブジェクトではない- ルールに
source/urls/where/relative_to/eagerness/referrer_policy/tag/requires/expects_no_vary_search/target_hint以外のキーが存在する sourceが文字列ではない、またはlist/document以外の値である- リストルール(明示または
urlsから推論)にurlsがない、またはwhereが存在する - ドキュメントルール(明示または
whereから推論)にwhereがない、またはurlsが存在する - ルールに
sourceがなく source を推論できない(urlsもwhereもない、または両方ある) urlsが JSON 配列ではない・空・非文字列または空文字列の要素を含むeagernessが文字列ではない、またはimmediate/eager/moderate/conservative以外の値であるwhereが JSON オブジェクトではない、または述語(and/or/not/href_matches/selector_matches)をちょうど 1 つ含まないand/or述語が JSON 配列ではない、または空であるhref_matches/selector_matchesのパターンが文字列でも文字列配列でもない・空・空文字列の要素を含む
❌ このルールに適合しない誤ったコードの例
<script type="speculationrules">
{
"prefetch": [{ "source": "list" }]
}
</script>
<script type="speculationrules">
{
"prefetch": [{ "source": "document", "where": {} }]
}
</script>
✅ このルールに適合する正しいコードの例
<script type="speculationrules">
{
"prefetch": [
{
"source": "document",
"where": {
"and": [{ "href_matches": "/*" }, { "not": { "selector_matches": ".no-prefetch" } }]
},
"eagerness": "moderate"
}
],
"prerender": [{ "source": "list", "urls": ["/next"] }]
}
</script>
Interface
{
"valid-speculation-rules": boolean
}
<script type="speculationrules"> 要素の本文を、Speculation Rules の仕様に基づき検証します。
Default Severity
error