Make the website faster by preloading pages on hover
This is a mini script like instantclick, but well-structured version:
- Script Sandboxing System
- Improved Script Registry
- Controlled Script Execution
- Script Context Management
- Global Variable Preservation
- Better Error Handling
- Script Dependency Management
- Link prefetching on hover/mousedown
- Fast page transitions
- History state management
- Script handling during transitions
- Enhance with new perf like DOM-Less feature & rewrite in ES6 - I think for myself
To use this library on your website:
- Include the JavaScript file in your HTML(header/footer):
<script src="instantview.js"></script>- Initialize it when the DOM is ready (HTML in header/footer):
<script>
document.addEventListener("DOMContentLoaded", function() {
InstantView.init();
});
</script>- Optional: Add configuration options
<script>
document.addEventListener("DOMContentLoaded", function() {
// Use mousedown instead of mouseover (faster perceived speed but less preloading)
InstantView.init("mousedown");
// Add a delay in milliseconds before preloading (reduce unnecessary requests)
InstantView.init(100);
// Use whitelist mode (only preload links with data-instant attribute)
InstantView.init(true);
// Combine options
InstantView.init(true, "mousedown", 50);
});
</script>- Optional: Listen for events
<script>
InstantView.on("change", function() {
// Page has changed
setupAnalytics();
});
InstantView.on("fetch", function() {
// Page fetch started
showCustomLoadingIndicator();
});
</script>Link: https://dev.lotusk08-github-io.pages.dev/
Read the WIKI
Thank to InstantClick & EGOIST libraries.
