Skip to content

Gives access to hovered links - in that moment we can prefetch data to improve next page loading for SPA apps

License

Notifications You must be signed in to change notification settings

gibkigonzo/instant-prefetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

instant-prefetch

Extension of well known InstantPage library. All kudos for (☞゚∀゚)☞ Alexandre Dieulot

import { init } from 'instant-prefetch'

init(
  (element) => {
    // access to link url
    console.log(element.href)
    // We can also add data attributes to element and then retrive it here
    // For example:
    // <a data-instant-prefetch='{"url": "/women.html", "type": "category"}' >
    if ('instantDataPrefetch' in linkElement.dataset) {
      try {
        const data = JSON.parse(linkElement.dataset['instantDataPrefetch'])
        console.log(data) // do something
      } catch (err) {}
    }
  },
  // optional
  // same as global options added for https://instant.page/ to <body>
  {
    allowQueryString: false, // same as 'data-instant-allow-query-string' added to body in InstantPage https://instant.page/blacklist
    allowExternalLinks: false, // same as 'data-instant-allow-external-links' added to body in InstantPage https://instant.page/blacklist
    useWhitelist: false, // same as 'data-instant-allow-external-links' added to body in InstantPage https://instant.page/blacklist
    mousedownShortcut: false, // same as 'data-instant-mousedown-shortcut' added to body in InstantPage https://instant.page/intensity
    intensity = '', // 'data-instant-intensity' added to body in InstantPage https://instant.page/intensity
  }
)

// next call for `init` will only reload listeners and IntersectionObserver but list of triggered links will remain the same

See more information on the original website: https://instant.page/

License

MIT © gibkigonzo.

About

Gives access to hovered links - in that moment we can prefetch data to improve next page loading for SPA apps

Resources

License

Stars

Watchers

Forks

Packages

No packages published