Skip to content

Repository files navigation

speculative

npm install speculative --save
varspeculative=require('speculative')speculative({href: 'http://google.com',rel: 'prerender'})

API

speculative(attributes)

attributes

rel

rel valueNatureBrowser action
prerenderspeculativeDNS lookup, TCP/TLS handshake, fetch data, execute scripts
preloadmandatoryDNS lookup, TCP/TLS handshake, fetch data
prefetchspeculativeDNS lookup, TCP/TLS handshake, fetch data
preconnectspeculativeDNS lookup, TCP/TLS handshake
dns-prefetchspeculativeDNS lookup

Examples

Speculating navigation

speculative({href: '/page/2',rel: 'prerender next',as: 'html',pr: .5})speculative({href: '/page/3',rel: 'prefetch',as: 'html',pr: .2})

Prefetching playlist tracks

speculative({href: './track-2.mp3',rel: 'prefetch',as: 'media',pr: .8})speculative({href: './track-3.mp3',rel: 'prefetch',as: 'media',pr: .3})

Prefetching an image

speculative({href: './hi-res.jpg',rel: 'prefetch',media: '(min-width: 60rem)',as: 'image'})

Prefetching JavaScript

speculative({href: 'https://code.jquery.com/jquery-3.1.0.slim.min.js',rel: 'prefetch',crossorigin: 'anonymous',as: 'script',pr: 1})

Prefetching CSS

speculative({href: '/animations.css',rel: 'prefetch',media: 'screen',as: 'style'})

Prefetch with care. Test for metered data usage

varcxn=require('cxn')varspeculative=cxn.metered() ? function(){} : require('speculative')

License

MIT

About

prerender, preconnect, preload, prefetch, dns-prefetch

Topics

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages