* The preloader searches for all anchor elements on the page every poll * interval, and, unless specified by data-prefetch, start a visibility observer * for that element. * * The href of the anchor is preloaded when the element becomes visible.
()
| 153 | * The href of the anchor is preloaded when the element becomes visible. |
| 154 | */ |
| 155 | function startPreloader() { |
| 156 | if (typeof document === 'undefined') { |
| 157 | return |
| 158 | } |
| 159 | const run = () => { |
| 160 | const els = [].slice.call(document.getElementsByTagName('a')) |
| 161 | |
| 162 | els.forEach(el => { |
| 163 | const href = el.getAttribute('href') |
| 164 | const prefetchOption = el.getAttribute('data-prefetch') |
| 165 | const shouldPrefetch = |
| 166 | !prefetchOption || |
| 167 | prefetchOption === 'true' || |
| 168 | prefetchOption === 'visible' |
| 169 | |
| 170 | if (href && shouldPrefetch) { |
| 171 | onVisible(el, () => prefetch(href)) |
| 172 | } |
| 173 | }) |
| 174 | } |
| 175 | |
| 176 | setInterval(run, Number(process.env.REACT_STATIC_PRELOAD_POLL_INTERVAL)) |
| 177 | } |
| 178 | |
| 179 | async function reloadClientData() { |
| 180 | console.log('React Static: Reloading Data...') |
no outgoing calls
no test coverage detected
searching dependent graphs…