npm install speculative --savevar speculative = require('speculative')
speculative({
href: 'http://google.com',
rel: 'prerender'
})href: URIrel: relationpr: probability number between0and1as: content typecrossorigin: CORS settingmedia: media query
rel value |
Nature | Browser action |
|---|---|---|
| prerender | speculative | DNS lookup, TCP/TLS handshake, fetch data, execute scripts |
| preload | mandatory | DNS lookup, TCP/TLS handshake, fetch data |
| prefetch | speculative | DNS lookup, TCP/TLS handshake, fetch data |
| preconnect | speculative | DNS lookup, TCP/TLS handshake |
| dns-prefetch | speculative | DNS lookup |
speculative({
href: '/page/2',
rel: 'prerender next',
as: 'html',
pr: .5
})
speculative({
href: '/page/3',
rel: 'prefetch',
as: 'html',
pr: .2
})speculative({
href: './track-2.mp3',
rel: 'prefetch',
as: 'media',
pr: .8
})
speculative({
href: './track-3.mp3',
rel: 'prefetch',
as: 'media',
pr: .3
})speculative({
href: './hi-res.jpg',
rel: 'prefetch',
media: '(min-width: 60rem)',
as: 'image'
})speculative({
href: 'https://code.jquery.com/jquery-3.1.0.slim.min.js',
rel: 'prefetch',
crossorigin: 'anonymous',
as: 'script',
pr: 1
})speculative({
href: '/animations.css',
rel: 'prefetch',
media: 'screen',
as: 'style'
})var cxn = require('cxn')
var speculative = cxn.metered() ? function() {} : require('speculative')MIT