Skip to main content

PDF Timing Options

Control when the PDF is generated by adding delays or cache management. These options ensure content is fully loaded and manage how PDFs are cached.

Timing Parameters

Delay (delay)

  • Default: 0 seconds
  • Description: Wait time before generating the PDF
  • Range: 0-60 seconds
  • Example: delay=5 waits 5 seconds
  • Note: Use edge endpoint for delays > 25 seconds

Timestamp (timestamp)

  • Default: None
  • Description: Force cache invalidation
  • Example: timestamp=1677649200
  • Purpose: Ensures fresh PDF generation

Usage Examples

Simple Delay

Wait for animations to complete:

https://cdn.capture.page/KEY/HASH/pdf?url=https://example.com&delay=3

Force Fresh Generation

Bypass cached version:

https://cdn.capture.page/KEY/HASH/pdf?url=https://example.com&timestamp=1677649200

Long Delay (Edge Endpoint)

For delays exceeding 25 seconds:

https://edge.capture.page/KEY/HASH/pdf?url=https://example.com&delay=45

Common Scenarios

Dynamic Content Loading

JavaScript-Heavy Sites

// React/Vue/Angular apps
&delay=3 // Allow app to initialize

// Data dashboards
&delay=5 // Wait for charts to render

// Lazy-loaded content
&delay=2 // Ensure images load

API-Driven Content

// Wait for API calls to complete
&delay=4

// Real-time data
&delay=6&timestamp=${Date.now()} // Fresh data each time

Animation and Transitions

CSS Animations

// Hero animations
&delay=2 // Wait for entrance animations

// Page transitions
&delay=1 // Allow smooth transitions to complete

// Loading states
&delay=3 // Skip loading spinners

Chart Rendering

// D3.js visualizations
&delay=4

// Chart.js animations
&delay=3

// Highcharts
&delay=2

Cache Management

How Caching Works

  1. PDF generated on first request
  2. Cached based on URL + all parameters
  3. Subsequent requests serve cached version
  4. Cache expires after 24 hours
  5. Timestamp parameter forces regeneration

Cache Strategies

Time-Based Invalidation

// Daily PDFs
const daily = new Date().toISOString().split('T')[0];
const url = `...&timestamp=${daily}`;

// Hourly updates
const hourly = new Date().getHours();
const url = `...&timestamp=${Date.now()}-${hourly}`;

// Every 15 minutes
const quarter = Math.floor(new Date().getMinutes() / 15);
const url = `...&timestamp=${Date.now()}-${quarter}`;

Content-Based Invalidation

// Based on data version
const dataVersion = getDataVersion();
const url = `...&timestamp=${dataVersion}`;

// Based on last update
const lastUpdate = getLastUpdateTime();
const url = `...&timestamp=${lastUpdate}`;

// Based on content hash
const contentHash = calculateContentHash();
const url = `...&timestamp=${contentHash}`;

Event-Based Invalidation

// After deployment
const deploymentId = getDeploymentId();
const url = `...&timestamp=deploy-${deploymentId}`;

// After data import
const importId = getLastImportId();
const url = `...&timestamp=import-${importId}`;

// After user action
const actionId = getUserActionId();
const url = `...&timestamp=action-${actionId}`;

Performance Optimization

Optimal Delay Values

Content TypeRecommended DelayReason
Static Pages0-1sMinimal JS
SPA Apps2-3sFramework init
Dashboards3-5sData loading
Animations2-4sAnimation completion
API Data4-6sNetwork requests

Delay vs Wait Strategies

// Fixed delay (simple but may be inefficient)
const fixedDelay = 5;

// Dynamic delay based on content
function calculateDelay(url) {
if (url.includes('dashboard')) return 5;
if (url.includes('report')) return 3;
if (url.includes('static')) return 1;
return 2;
}

// Progressive delays for retries
function getRetryDelay(attempt) {
return Math.min(attempt * 2, 10);
}

Edge Endpoint Usage

Use edge endpoint when:

// Long data processing
if (processingTime > 25) {
endpoint = 'edge.capture.page';
delay = processingTime;
}

// Complex reports
if (reportComplexity === 'high') {
endpoint = 'edge.capture.page';
delay = 45;
}

// Batch operations
if (batchSize > 10) {
endpoint = 'edge.capture.page';
delay = 60;
}

Advanced Timing Patterns

Scheduled Generation

// Pre-generate PDFs during off-peak
async function preGeneratePDFs() {
const urls = getScheduledUrls();
const nightTime = new Date().getHours() < 6;

if (nightTime) {
for (const url of urls) {
await generatePDF(url, {
delay: 5,
timestamp: new Date().toISOString()
});
await sleep(2000); // Prevent overload
}
}
}

Smart Caching

// Intelligent cache invalidation
class PDFCacheManager {
shouldInvalidate(url, lastGenerated) {
// Always fresh for critical docs
if (url.includes('financial')) return true;

// Time-based for reports
if (url.includes('report')) {
const hoursSince = (Date.now() - lastGenerated) / 3600000;
return hoursSince > 4;
}

// Weekly for static content
const daysSince = (Date.now() - lastGenerated) / 86400000;
return daysSince > 7;
}
}

Conditional Delays

// Adjust delay based on time of day
function getDelayForTime() {
const hour = new Date().getHours();

// Peak hours need more time
if (hour >= 9 && hour <= 17) {
return 5;
}

// Off-peak is faster
return 2;
}

// Adjust delay based on server load
async function getDelayForLoad() {
const load = await getServerLoad();

if (load > 0.8) return 8;
if (load > 0.5) return 5;
return 2;
}

Troubleshooting

Content Not Fully Loaded

If PDFs show partial content:

// Increase delay
&delay=5 // Instead of 2

// For very slow sites
https://edge.capture.page/...&delay=30

// Check network panel in browser
// to determine actual load time

Cache Not Updating

If changes don't appear:

// Force fresh generation
&timestamp=${Date.now()}

// Use more specific cache key
&timestamp=${contentVersion}-${userRole}

// Clear at regular intervals
&timestamp=${Math.floor(Date.now() / 3600000)}

Timeout Errors

For long-running operations:

// Switch to edge endpoint
https://edge.capture.page/KEY/HASH/pdf?url=...&delay=45

// Break into smaller operations
// Generate sections separately

Best Practices

1. Choose Appropriate Delays

// Start with minimal delay
let delay = 1;

// Increase based on testing
if (hasAnimations) delay += 1;
if (hasAPIcalls) delay += 2;
if (hasLazyLoad) delay += 1;

2. Implement Smart Caching

// Cache static content longer
const cacheStrategy = {
static: 86400, // 24 hours
dynamic: 3600, // 1 hour
realtime: 300, // 5 minutes
critical: 0 // No cache
};

3. Monitor Performance

// Track generation times
async function generateWithMetrics(url, options) {
const start = Date.now();
const result = await generatePDF(url, options);
const duration = Date.now() - start;

logMetric('pdf_generation_time', duration);

if (duration > 30000) {
console.warn('Consider using edge endpoint');
}

return result;
}

4. Handle Edge Cases

// Retry with increased delay
async function generateWithRetry(url, maxAttempts = 3) {
for (let i = 0; i < maxAttempts; i++) {
try {
const delay = i * 2; // Progressive delay
return await generatePDF(url, { delay });
} catch (error) {
if (i === maxAttempts - 1) throw error;
await sleep(1000);
}
}
}

Optimization Tips

Reduce Delays

  1. Optimize source pages: Faster loading = shorter delays
  2. Preload resources: Reduce dynamic loading
  3. Use static rendering: Server-side rendering when possible
  4. Minimize API calls: Batch or cache data

Cache Effectively

  1. Identify static content: Cache longer
  2. Version dynamic content: Use semantic timestamps
  3. Implement cache warming: Pre-generate popular PDFs
  4. Monitor cache hit rate: Optimize cache strategy

See Also