whmcs-prefetching
Resource prefetching for WHMCS
SKILL.mdskills/whmcs-prefetching/SKILL.md
GitHubWHMCS Resource Prefetching Skill
Overview
This skill provides patterns for resource prefetching in WHMCS.
Implementation Patterns
Prefetch Manager
<?php
/**
* WHMCS Resource Prefetching
* Prefetches resources for faster navigation
*/
namespace WHMCS\Module\Performance\Prefetch;
class PrefetchManager {
/**
* Generate prefetch hints
*/
public function generatePrefetchHints(array $pages): string {
$hints = [];
foreach ($pages as $page) {
$hints[] = "<link rel=\"prefetch\" href=\"{$page}\">";
}
return implode("\n", $hints);
}
/**
* Prefetch for navigation prediction
*/
public function predictAndPrefetch(): string {
return <<<SCRIPT
document.addEventListener("mouseover", function(e) {
const link = e.target.closest("a");
if (link && link.href) {
const prefetch = document.createElement("link");
prefetch.rel = "prefetch";
prefetch.href = link.href;
document.head.appendChild(prefetch);
}
}, { passive: true });
SCRIPT;
}
}
Best Practices
- DNS Prefetch: Prefetch DNS for external domains
- Preconnect: Establish early connections
- Prefetch Pages: Prefetch likely next pages
- Predictive: Use navigation prediction
- Budget: Don't prefetch too aggressively
Related Skills
- whmcs-http2-push
- whmcs-lazy-loading
- whmcs-caching-strategies
- whmcs-browser-caching