MCPcopy Create free account
hub / github.com/react-static/react-static / startPreloader

Function startPreloader

packages/react-static/src/browser/index.js:155–177  ·  view source on GitHub ↗

* 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.

()

Source from the content-addressed store, hash-verified

153 * The href of the anchor is preloaded when the element becomes visible.
154 */
155function 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
179async function reloadClientData() {
180 console.log('React Static: Reloading Data...')

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…