Beast Mode
Beast Mode is SpeedMate's aggressive JavaScript delay strategy that defers all script execution until user interaction.
What is Beast Mode?
Unlike Safe Mode which uses standard optimizations, Beast Mode delays JavaScript execution until the first user interaction (click, scroll, or keypress):
- Delayed Execution: All
<script>tags converted to delayed format - User-Triggered: Scripts execute on first click/scroll/keypress
- LCP Optimization: Prioritizes visual content loading
- Aggressive: Maximum performance at cost of delayed interactivity
How It Works
JavaScript Delay Flow
mermaid
flowchart TB
Start([Page Load]) --> Parse[Parse HTML]
Parse --> FindScripts{Find Script Tags}
FindScripts --> ProcessScripts[Process Each Script]
ProcessScripts --> CheckType{Script Type?}
CheckType -->|Inline| ConvertInline[Convert to type='speedmate-delayed']
CheckType -->|External| ConvertExternal[Convert src to data-speedmate-src]
CheckType -->|Excluded| Skip[Keep Original]
ConvertInline --> StoreScript[Store in Delayed Queue]
ConvertExternal --> StoreScript
Skip --> Continue
StoreScript --> WaitInteraction{Wait for<br/>User Action}
WaitInteraction -->|Click| Trigger[Trigger Event]
WaitInteraction -->|Scroll| Trigger
WaitInteraction -->|Keypress| Trigger
Trigger --> ExecuteAll[Execute All Delayed Scripts]
ExecuteAll --> RestoreOriginal[Restore Original Script Tags]
RestoreOriginal --> RunScripts[Run Scripts in Order]
Continue & RunScripts --> End([Page Interactive])
style Start fill:#4A90E2
style WaitInteraction fill:#F5A623
style ExecuteAll fill:#7ED321
style End fill:#4A90E2Performance Impact
mermaid
gantt
title Page Load Timeline Comparison
dateFormat X
axisFormat %s
section Safe Mode
HTML Parse :0, 200
CSS Load :200, 400
JS Download :400, 800
JS Parse/Execute :800, 1200
LCP :1200, 1400
FCP :400, 600
Interactive :1200, 1400
section Beast Mode
HTML Parse :0, 200
CSS Load :200, 400
LCP :400, 600
FCP :200, 400
User Interaction :600, 1000
JS Download :1000, 1400
JS Parse/Execute :1400, 1800
Interactive :1400, 1800How It Works (Text)
User Request → Page Load → Parse HTML
↓
Find <script> tags
↓
Convert to delayed format
↓
Wait for user interaction
↓
(click/scroll/keypress)
↓
Execute all scriptsScoring Algorithm
Beast Mode scores pages based on:
- Request Count: Number of requests in time window
- Request Rate: Requests per minute
- Response Time: Average page generation time
- Resource Usage: Memory and database query count
Formula:
score = (requests * 10) + (rate * 5) + (response_time / 100)Threshold: score >= 50 triggers auto-caching
Configuration
Enable Beast Mode
php
update_option('speedmate_settings', [
'mode' => 'beast',
'beast_threshold' => 50, // Minimum score
'beast_time_window' => 3600, // 1 hour window
'beast_whitelist' => [], // Always cache
'beast_blacklist' => [], // Never cache
]);Via WordPress Admin
- Navigate to Settings > SpeedMate
- Set Mode to
Beast - Configure threshold and whitelist
- Save changes
Whitelist Rules
Force-cache specific patterns:
php
update_option('speedmate_settings', [
'beast_whitelist' => [
'/blog/*', // All blog posts
'/category/*', // All categories
'/tag/*', // All tags
'/shop/*', // All shop pages
'/', // Homepage
]
]);Programmatic Whitelist
php
add_filter('speedmate_beast_whitelist', function($whitelist) {
// Add custom post type
$whitelist[] = '/products/*';
// Add specific pages
$whitelist[] = '/about';
$whitelist[] = '/contact';
return $whitelist;
});Blacklist Rules
Exclude specific patterns from Beast Mode:
php
update_option('speedmate_settings', [
'beast_blacklist' => [
'/checkout/*', // E-commerce checkout
'/cart/*', // Shopping cart
'/my-account/*', // User account pages
'/admin/*', // Admin pages
]
]);Default Exclusions
Beast Mode automatically excludes:
- Admin pages (
/wp-admin/*) - User account pages
- Checkout/cart pages (WooCommerce)
- Search results
- Preview pages
- Password-protected pages
Traffic Analysis
Real-Time Monitoring
bash
# View current traffic stats
wp speedmate stats
# Monitor Beast Mode decisions
tail -f wp-content/speedmate.log | grep beastTraffic Data Structure
json
{
"url": "/blog/post-name",
"hits": 142,
"rate": 2.3,
"avg_response": 450,
"score": 87,
"cached": true,
"cache_time": "2026-01-22T10:30:00Z"
}Performance Metrics
Before Beast Mode
High Traffic Page:
- Requests: 1000/hour
- Response Time: 500ms
- Database Queries: 80/request
- Memory Usage: 80MB
- Total Time: 500 secondsAfter Beast Mode
High Traffic Page:
- Requests: 1000/hour
- Response Time: 3ms (cached)
- Database Queries: 0/request
- Memory Usage: 5MB
- Total Time: 3 secondsPerformance Gain: 99.4% faster
Advanced Features
Adaptive Caching
Beast Mode adapts cache strategy based on:
- Time of Day: Higher threshold during low traffic
- Day of Week: Lower threshold on weekends
- Seasonal Traffic: Adjusts for traffic spikes
- Resource Availability: Reduces caching under load
php
add_filter('speedmate_beast_threshold', function($threshold) {
$hour = (int) date('H');
// Lower threshold during business hours
if ($hour >= 9 && $hour <= 17) {
return $threshold * 0.8;
}
// Higher threshold at night
return $threshold * 1.2;
});Cache Warming Integration
Beast Mode automatically triggers cache warming for:
- Related posts
- Category archives
- Author pages
- Next/previous pagination
Dynamic TTL
Cache lifetime adjusts based on update frequency:
php
add_filter('speedmate_beast_ttl', function($ttl, $url) {
// Longer TTL for static pages
if (preg_match('/^\/(about|contact)/', $url)) {
return 86400; // 24 hours
}
// Shorter TTL for blog posts
if (preg_match('/^\/blog\//', $url)) {
return 3600; // 1 hour
}
return $ttl;
}, 10, 2);Monitoring
Dashboard Widget
View Beast Mode stats in WordPress admin:
Beast Mode Status
━━━━━━━━━━━━━━━━━━━━
Status: Active
Auto-Cached: 142 pages
Traffic Hits: 1,245
Avg Score: 67
Cache Hit Rate: 94.2%WP-CLI Monitoring
bash
# Beast Mode stats
wp speedmate info | grep -A5 "Beast Mode"
# Top scoring pages
wp eval "print_r(\SpeedMate\Utils\Stats::get_top_scored());"
# Recent auto-cached pages
wp eval "print_r(\SpeedMate\Utils\Stats::get_recent_cached());"Logging
php
// Enable Beast Mode logging
update_option('speedmate_settings', [
'logging_enabled' => true,
'log_level' => 'info'
]);Log entries:
json
{
"level": "info",
"event": "beast_auto_cache",
"url": "/blog/popular-post",
"score": 87,
"threshold": 50,
"timestamp": "2026-01-22T10:30:00Z"
}Best Practices
- Start with Conservative Threshold: Use default 50, adjust based on traffic
- Monitor Regularly: Check cache hit rates and scores
- Use Whitelist for Critical Pages: Force-cache homepage, landing pages
- Blacklist User-Specific Content: Exclude checkout, account pages
- Enable Cache Warming: Pre-cache likely navigation paths
- Review Logs Periodically: Identify patterns and adjust rules
Troubleshooting
Pages Not Auto-Caching
- Check traffic meets threshold
- Verify page not in blacklist
- Review exclusion rules
- Check cache directory permissions
Too Many Pages Cached
- Increase threshold
- Add patterns to blacklist
- Reduce time window
- Enable stricter scoring
Cache Thrashing
- Increase TTL
- Reduce auto-invalidation triggers
- Use cache warming
- Review whitelist rules