|
| 1 | +# prefetch.ru — Instant Page Loading for Russian Web |
| 2 | + |
| 3 | +Prefetch pages 65ms before user clicks. Pre-loads links on hover with smart fallbacks for iOS/Safari, optimized for Russian browsers (Yandex.Browser, Atom), CMS platforms (1C-Bitrix, Tilda), and e-commerce. Works everywhere with zero configuration. |
| 4 | + |
| 5 | +## What It Does |
| 6 | + |
| 7 | +- Pre-loads pages on mouse hover (65ms before click) |
| 8 | +- Speeds up perceived page navigation to near-instant |
| 9 | +- Improves Core Web Vitals (LCP, INP, CLS) |
| 10 | +- Works across all modern browsers with automatic fallbacks |
| 11 | +- Respects user privacy and network conditions |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### CDN (Recommended) |
| 16 | + |
| 17 | +```html |
| 18 | +<script src="//cdn.prefetch.ru/v1.1.2/prefetch.min.js" |
| 19 | + integrity="sha384-BDLxwRTwyIWnAEmc+2Rkw41jVvctV3HxxTu1ryrmagtHh18GekSP+bfqy5/YswEW" |
| 20 | + crossorigin="anonymous" |
| 21 | + type="module" |
| 22 | + defer></script> |
| 23 | +``` |
| 24 | + |
| 25 | +### npm |
| 26 | + |
| 27 | +```bash |
| 28 | +npm install @prefetchru/prefetch |
| 29 | +``` |
| 30 | + |
| 31 | +```javascript |
| 32 | +// ESM |
| 33 | +import '@prefetchru/prefetch' |
| 34 | + |
| 35 | +// CommonJS |
| 36 | +require('@prefetchru/prefetch') |
| 37 | +``` |
| 38 | + |
| 39 | +## Configuration |
| 40 | + |
| 41 | +Configure via data attributes on `<body>`: |
| 42 | + |
| 43 | +```html |
| 44 | +<body data-prefetch-specrules |
| 45 | + data-prefetch-allow-query-string |
| 46 | + data-prefetch-allow-external-links> |
| 47 | +``` |
| 48 | + |
| 49 | +### Available Options |
| 50 | + |
| 51 | +| Attribute | Values | Description | |
| 52 | +|-----------|--------|-------------| |
| 53 | +| `data-prefetch-intensity` | `65` (default), `mousedown`, `viewport`, `viewport-all` | Hover delay in ms or trigger mode | |
| 54 | +| `data-prefetch-specrules` | empty, `prerender`, `no` | Enable Speculation Rules API | |
| 55 | +| `data-prefetch-specrules-fallback` | — | Enable fallback when using Speculation Rules | |
| 56 | +| `data-prefetch-whitelist` | — | Whitelist mode (only links with `data-prefetch`) | |
| 57 | +| `data-prefetch-allow-query-string` | — | Allow links with query parameters | |
| 58 | +| `data-prefetch-allow-external-links` | — | Allow external domains | |
| 59 | +| `data-prefetch-observe-dom` | — | Watch for new links (SPA support) | |
| 60 | +| `data-prefetch-nonce` | `"abc123"` | CSP nonce value | |
| 61 | + |
| 62 | +### Link-Level Control |
| 63 | + |
| 64 | +```html |
| 65 | +<!-- Force prefetch for specific link --> |
| 66 | +<a href="/catalog" data-prefetch>Catalog</a> |
| 67 | + |
| 68 | +<!-- Disable prefetch for specific link --> |
| 69 | +<a href="/logout" data-no-prefetch>Logout</a> |
| 70 | + |
| 71 | +<!-- Enable prerender for specific link --> |
| 72 | +<a href="/pricing" data-prefetch-prerender>Pricing</a> |
| 73 | +``` |
| 74 | + |
| 75 | +## JavaScript API |
| 76 | + |
| 77 | +```javascript |
| 78 | +// Check version |
| 79 | +console.log(PrefetchRu.version) // "1.1.2" |
| 80 | + |
| 81 | +// Manually prefetch a URL |
| 82 | +PrefetchRu.preload('/catalog/product-123') |
| 83 | + |
| 84 | +// Update state after SPA navigation |
| 85 | +PrefetchRu.refresh() |
| 86 | + |
| 87 | +// Disable the library |
| 88 | +PrefetchRu.destroy() |
| 89 | +``` |
| 90 | + |
| 91 | +## How It Works |
| 92 | + |
| 93 | +### Timeline |
| 94 | + |
| 95 | +``` |
| 96 | + 0ms → Mouse hover starts |
| 97 | + 65ms → Prefetch begins |
| 98 | +200ms → User clicks |
| 99 | + ~0ms → Page loads from cache |
| 100 | +``` |
| 101 | + |
| 102 | +### Prefetch Methods (Auto-Selected) |
| 103 | + |
| 104 | +1. **Speculation Rules API** (Chromium 109+) — Modern API for prefetch/prerender |
| 105 | +2. **Link Prefetch** (`<link rel="prefetch">`) — Standard method for Firefox |
| 106 | +3. **Fetch Fallback** — For iOS/Safari via `fetch()` with caching |
| 107 | + |
| 108 | +## Automatic Exclusions |
| 109 | + |
| 110 | +The library automatically excludes: |
| 111 | + |
| 112 | +- Dangerous paths: `/login`, `/logout`, `/auth`, `/register`, `/cart`, `/basket`, `/add`, `/delete`, `/remove` |
| 113 | +- File downloads: `.pdf`, `.doc`, `.docx`, `.xls`, `.xlsx`, `.zip`, `.rar`, `.exe` |
| 114 | +- Analytics links: Yandex.Metrika, Google Analytics, Matomo classes |
| 115 | +- Same-page anchors |
| 116 | +- Links with `target="_blank"` or `download` attribute |
| 117 | + |
| 118 | +## Platform Support |
| 119 | + |
| 120 | +### 1C-Bitrix |
| 121 | +- Excludes `/bitrix/` URLs and `sessid=` parameters |
| 122 | +- Skips `bx-ajax` class links |
| 123 | +- Auto-enables DOM observation |
| 124 | + |
| 125 | +### Tilda |
| 126 | +- Excludes `#popup:` and `#rec` anchors |
| 127 | +- Auto-enables DOM observation |
| 128 | +- Increased hover delay (100ms) |
| 129 | + |
| 130 | +## Browser Support |
| 131 | + |
| 132 | +| Browser | Method | Status | |
| 133 | +|---------|--------|--------| |
| 134 | +| Chrome 109+ | Speculation Rules API | Full support | |
| 135 | +| Yandex.Browser | Speculation Rules API | Full support | |
| 136 | +| Atom (VK) | Speculation Rules API | Full support | |
| 137 | +| Safari / iOS | fetch fallback | Works | |
| 138 | +| Firefox | `rel="prefetch"` | Works | |
| 139 | +| Edge | Speculation Rules API | Full support | |
| 140 | + |
| 141 | +## Network Awareness |
| 142 | + |
| 143 | +- Disables on slow connections (2G/3G) |
| 144 | +- Respects Save-Data header |
| 145 | +- Limits concurrent requests (max 4) |
| 146 | +- Queue management (max 50 pending) |
| 147 | + |
| 148 | +## Privacy & Security |
| 149 | + |
| 150 | +- No analytics or tracking |
| 151 | +- Works entirely client-side |
| 152 | +- SRI hash verification |
| 153 | +- Cross-origin requests use `no-referrer` policy |
| 154 | +- External requests omit credentials |
| 155 | + |
| 156 | +## Size & Performance |
| 157 | + |
| 158 | +- ~4KB gzipped |
| 159 | +- Zero dependencies |
| 160 | +- Non-blocking (defer/module) |
| 161 | +- Removes Speculation Rules scripts after insertion (keeps DOM clean) |
| 162 | + |
| 163 | +## Links |
| 164 | + |
| 165 | +- Website: https://prefetch.ru |
| 166 | +- GitHub: https://github.com/prefetch-ru/prefetch |
| 167 | +- npm: https://www.npmjs.com/package/@prefetchru/prefetch |
| 168 | + |
| 169 | +## License |
| 170 | + |
| 171 | +MIT License © 2026 Sergey Makarov |
0 commit comments