Skip to content

Commit

Permalink
Add initial speculation rules implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
damiendart committed Nov 21, 2024
1 parent c74589c commit 03fe5c7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions private/apache2/directory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@
RewriteCond %1.%2 -f
RewriteRule ^(.*)\.\d{14}\.(avif|css|js|png|svg|webp|woff|woff2)$ $1.${RELEASE_TIMESTAMP}.$2 [L,NE,R=permanent]
</IfModule>

<FilesMatch "speculation-rules\.json">
Header set Content-Type: "application/speculationrules+json"
</FilesMatch>

<FilesMatch ".*\.html$">
Header set Speculation-Rules: '"/speculation-rules.json"'
</FilesMatch>
3 changes: 2 additions & 1 deletion src/ssg/ValueObjects/InputFileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public function getSitemapEntries(): array
\assert(\is_string($slug));

if (
'robots.txt' === $slug
'speculation-rules.json' === $slug
|| 'robots.txt' === $slug
|| 'sitemap.xml' === $slug
|| str_starts_with($slug, 'google')
|| str_ends_with($slug, '.atom')
Expand Down
18 changes: 18 additions & 0 deletions src/ssg/input/speculation-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"prefetch": [
{
"where": {
"selector_matches": "a[href^='/']"
},
"eagerness": "immediate"
}
],
"prerender": [
{
"where": {
"selector_matches": "a[href^='/']"
},
"eagerness": "moderate"
}
]
}

0 comments on commit 03fe5c7

Please sign in to comment.