传统流程:
用户请求 → 缓存未命中 → 回源获取 → 缓存存储 → 响应
预取流程:
预取任务 → 回源获取 → 缓存存储(就绪)
用户请求 → 缓存命中 → 即时响应
| Advantages: | Description |
|---|---|
| Eliminate cold starts | First-time visitors can also get cached content |
| Faster page loading | No back-to-origin round-trip delays |
| Predictable performance | Consistent response times |
| Source Protection | Distribute the load over different times |
Prefetch the specified URL:
{
"urls": [
"https://example.com/",
"https://example.com/products",
"https://example.com/about",
"https://example.com/css/styles.css",
"https://example.com/js/app.js"
]
}
Best for: Known key pages, landing pages, campaign pages
Automatically prefetch URLs from your sitemap:
站点地图 URL:https://example.com/sitemap.xml
Sudun parses your sitemap and prefetches all listed URLs:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/page1</loc>
<lastmod>2024-01-15</lastmod>
</url>
<url>
<loc>https://example.com/page2</loc>
</url>
</urlset>
Best for: Site-wide warm-ups, SEO-critical pages
Automatically discover and prefetch link content:
{
"start_url": "https://example.com/",
"depth": 2,
"max_urls": 100
}
Crawlers follow links to discover content:
深度 0:首页
深度 1:首页链接的页面
深度 2:深度 1 页面链接的页面
Best for: Dynamic websites, discovering new content
- Source: URL list, sitemap, or crawler
- Plan: One-time or periodic
- Options: Request header, region, number of concurrency
| options | Description | Default |
|---|---|---|
| area | Access points where the prefetch content will be deposited | All areas |
| Concurrent numbers | The number of parallel requests made to the origin server | 5 |
| Request header | Custom request header for prefetching requests | None |
| Ignore Robots | Skip robots.txt restrictions | Nope |
Prefetch to a specified geographic region:
{
"urls": ["https://example.com/"],
"regions": ["us-east", "eu-west", "asia-pacific"]
}
Available Regions:
| Region ID | location |
|---|---|
| us-east | Eastern North America |
| us-west | Western North America |
| eu-west | Western Europe |
| eu-central | Central Europe |
| asia-pacific | Asia Pacific |
| asia-south | South Asia |
Run prefetch immediately or at a scheduled time:
{
"schedule": {
"type": "once",
"run_at": "2024-01-15T06:00:00Z"
}
}
Set up automatic periodic prefetching:
{
"schedule": {
"type": "recurring",
"interval": "daily",
"time": "04:00",
"timezone": "UTC"
}
}
Plan Options:
| Interval | Description | Usage scenarios |
|---|---|---|
| hourly | Once an hour | Frequently updated content |
| daily | Once a day | Standard website |
| weekly | Once a week | Static content |
| custom | Cron expressions | Complex plans |
For advanced scheduling:
{
"schedule": {
"type": "cron",
"expression": "0 */6 * * *"
}
}
Common patterns:
0 4 * * * - 4 a.m. every day0 */2 * * * - Every 2 hours0 0 * * 0 - Every SundaySend specific headers at prefetching:
{
"headers": {
"Accept-Language": "en-US",
"Accept-Encoding": "gzip, br",
"X-Prefetch": "true"
}
}
Configure the prefetch user agent:
{
"user_agent": "Sudun-Prefetch/1.0"
}
Tip: Your origin server can detect prefetch requests through a user agent or custom headers and log them separately.
Automatic prefetching after deployment:
# CI/CD 集成
- name: 部署
run: deploy-script.sh
- name: 预热缓存
run: |
curl -X POST https://api.Sudun.com/v1/domains/example.com/prefetch \
-H "Authorization: Bearer $API_KEY" \
-d '{"sitemap": "https://example.com/sitemap.xml"}'
Triggering prefetching via webhook:
curl -X POST https://api.Sudun.com/v1/domains/example.com/prefetch/trigger \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"job_id": "prefetch-job-123"}'
Pre-fetch when content changes:
{
"trigger": {
"type": "purge",
"action": "prefetch_after_purge"
}
}
Track prefetching task progress:
| state | Description |
|---|---|
| Waiting | Tasks are queued |
| in operation | Prefetching is in progress |
| was done | All URLs are prefetched |
| Failed | Task Failure (View Error) |
| Partially completed | Some URLs failed |
View metrics in the dashboard:
{
"job_id": "pf-abc123",
"status": "completed",
"started_at": "2024-01-15T04:00:00Z",
"completed_at": "2024-01-15T04:05:32Z",
"stats": {
"total_urls": 150,
"successful": 148,
"failed": 2,
"skipped": 0
}
}
Start by prefetching the most important pages:
{
"urls": [
{"url": "https://example.com/", "priority": "high"},
{"url": "https://example.com/products", "priority": "high"},
{"url": "https://example.com/blog", "priority": "medium"},
{"url": "https://example.com/about", "priority": "low"}
]
}
Configure concurrency to avoid overloading the origin server:
{
"concurrency": 3,
"rate_limit": "10/秒"
}
Run prefetching when traffic is at its lowest:
高峰时段:上午 9 点 - 下午 6 点
预取窗口:凌晨 2 点 - 凌晨 5 点
Skip URLs that shouldn't be prefetched:
{
"exclude_patterns": [
"/api/*",
"/admin/*",
"*.json",
"*?session=*"
]
}
If prefetching overloads the origin:
If the contents are not cached after prefetching:
curl -X POST https://api.Sudun.com/v1/domains/example.com/prefetch \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": [
"https://example.com/",
"https://example.com/products"
],
"regions": ["us-east", "eu-west"],
"concurrency": 5
}'
curl -X POST https://api.Sudun.com/v1/domains/example.com/prefetch \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"sitemap": "https://example.com/sitemap.xml",
"schedule": {
"type": "daily",
"time": "04:00"
}
}'
curl -X GET https://api.Sudun.com/v1/domains/example.com/prefetch/job-123 \
-H "Authorization: Bearer YOUR_API_KEY"
Need help with content prefetching? Please contact admin@jindundun.com