{"id":16760450,"url":"https://github.com/ryanve/speculative","last_synced_at":"2025-04-10T17:37:19.712Z","repository":{"id":57367232,"uuid":"67572659","full_name":"ryanve/speculative","owner":"ryanve","description":"prerender, preconnect, preload, prefetch, dns-prefetch","archived":false,"fork":false,"pushed_at":"2016-09-09T06:38:58.000Z","size":6,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T18:56:27.580Z","etag":null,"topics":["dns-prefetch","javascript","preconnect","prefetch","preload","prerender"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/speculative","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ryanve.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-07T04:41:07.000Z","updated_at":"2023-11-11T07:35:08.000Z","dependencies_parsed_at":"2022-08-23T20:10:16.764Z","dependency_job_id":null,"html_url":"https://github.com/ryanve/speculative","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fspeculative","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fspeculative/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fspeculative/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ryanve%2Fspeculative/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ryanve","download_url":"https://codeload.github.com/ryanve/speculative/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248262035,"owners_count":21074236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns-prefetch","javascript","preconnect","prefetch","preload","prerender"],"created_at":"2024-10-13T04:23:34.614Z","updated_at":"2025-04-10T17:37:19.693Z","avatar_url":"https://github.com/ryanve.png","language":"JavaScript","readme":"# speculative\n\n```sh\nnpm install speculative --save\n```\n\n```js\nvar speculative = require('speculative')\n\nspeculative({\n  href: 'http://google.com',\n  rel: 'prerender'\n})\n```\n\n## API\n### `speculative(attributes)`\n\n#### `attributes`\n- `href`: URI\n- `rel`: relation\n- `pr`: probability number between `0` and `1`\n- `as`: [content type](https://www.w3.org/TR/preload/#link-element-interface-extensions)\n- `crossorigin`: [CORS setting](https://html.spec.whatwg.org/multipage/infrastructure.html#cors-settings-attributes)\n- `media`: media query\n\n#### `rel`\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth scope=\"col\"\u003e\u003ccode\u003erel\u003c/code\u003e value\u003c/th\u003e\n    \u003cth scope=\"col\"\u003eNature\u003c/th\u003e\n    \u003cth scope=\"col\"\u003eBrowser action\u003c/th\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"http://w3c.github.io/resource-hints/#prerender\"\u003eprerender\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003especulative\u003c/td\u003e\n    \u003ctd\u003eDNS lookup, TCP/TLS handshake, fetch data, execute scripts\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"https://www.w3.org/TR/preload/#link-type-preload\"\u003epreload\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003emandatory\u003c/td\u003e\n    \u003ctd\u003eDNS lookup, TCP/TLS handshake, fetch data\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"http://w3c.github.io/resource-hints/#prefetch\"\u003eprefetch\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003especulative\u003c/td\u003e\n    \u003ctd\u003eDNS lookup, TCP/TLS handshake, fetch data\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"http://w3c.github.io/resource-hints/#preconnect\"\u003epreconnect\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003especulative\u003c/td\u003e\n    \u003ctd\u003eDNS lookup, TCP/TLS handshake\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003ca href=\"http://w3c.github.io/resource-hints/#dns-prefetch\"\u003edns-prefetch\u003c/a\u003e\u003c/td\u003e\n    \u003ctd\u003especulative\u003c/td\u003e\n    \u003ctd\u003eDNS lookup\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n## Examples\n\n### Speculating navigation\n```js\nspeculative({\n  href: '/page/2',\n  rel: 'prerender next',\n  as: 'html',\n  pr: .5\n})\n\nspeculative({\n  href: '/page/3',\n  rel: 'prefetch',\n  as: 'html',\n  pr: .2\n})\n```\n\n### Prefetching playlist tracks\n```js\nspeculative({\n  href: './track-2.mp3',\n  rel: 'prefetch',\n  as: 'media',\n  pr: .8\n})\n\nspeculative({\n  href: './track-3.mp3',\n  rel: 'prefetch',\n  as: 'media',\n  pr: .3\n})\n```\n\n### Prefetching an image\n```js\nspeculative({\n  href: './hi-res.jpg',\n  rel: 'prefetch',\n  media: '(min-width: 60rem)',\n  as: 'image'\n})\n```\n\n### Prefetching JavaScript\n```js\nspeculative({\n  href: 'https://code.jquery.com/jquery-3.1.0.slim.min.js',\n  rel: 'prefetch',\n  crossorigin: 'anonymous',\n  as: 'script',\n  pr: 1\n})\n```\n\n### Prefetching CSS\n```js\nspeculative({\n  href: '/animations.css',\n  rel: 'prefetch',\n  media: 'screen',\n  as: 'style'\n})\n```\n\n### **Prefetch with care**. Test for metered data usage\n\n```js\nvar cxn = require('cxn')\nvar speculative = cxn.metered() ? function() {} : require('speculative')\n```\n\n## License\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanve%2Fspeculative","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fryanve%2Fspeculative","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fryanve%2Fspeculative/lists"}