{"id":27952076,"url":"https://github.com/swup/preload-plugin","last_synced_at":"2025-10-05T06:11:18.144Z","repository":{"id":34865664,"uuid":"185013818","full_name":"swup/preload-plugin","owner":"swup","description":"A swup plugin for preloading pages to speed up navigation 🚀","archived":false,"fork":false,"pushed_at":"2025-02-05T06:48:53.000Z","size":1543,"stargazers_count":14,"open_issues_count":3,"forks_count":14,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T08:18:07.584Z","etag":null,"topics":["page-transitions","plugin","prefetch","preload","speed","swup"],"latest_commit_sha":null,"homepage":"https://swup.js.org/plugins/preload-plugin","language":"TypeScript","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/swup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["gmrchk","daun","hirasso"],"open_collective":"swup"}},"created_at":"2019-05-05T10:03:58.000Z","updated_at":"2025-02-05T06:48:49.000Z","dependencies_parsed_at":"2023-02-16T07:45:22.379Z","dependency_job_id":"c99ee6dc-c4fe-44ff-af58-cda584cc18d0","html_url":"https://github.com/swup/preload-plugin","commit_stats":{"total_commits":294,"total_committers":9,"mean_commits":"32.666666666666664","dds":0.4693877551020408,"last_synced_commit":"d0b76d8c268dd25a584f37c5050a28d5e0152e02"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swup%2Fpreload-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swup%2Fpreload-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swup%2Fpreload-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swup%2Fpreload-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swup","download_url":"https://codeload.github.com/swup/preload-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252914707,"owners_count":21824422,"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":["page-transitions","plugin","prefetch","preload","speed","swup"],"created_at":"2025-05-07T16:27:29.699Z","updated_at":"2025-10-05T06:11:12.942Z","avatar_url":"https://github.com/swup.png","language":"TypeScript","readme":"# Swup Preload Plugin\n\nA [swup](https://swup.js.org) plugin for preloading pages and faster navigation.\n\n- Links with a `data-swup-preload` attribute will be preloaded automatically\n- Hovering a link on pointer devices will preload that link's URL, speeding up load time by a few 100ms. To save server resources, the number of simultaneous preload requests is limited to 5 by default.\n- Touch devices will instead preload links at the start of touch events, giving a ~80ms speed-up\n- Optionally preload links as they become visible in the viewport\n\n## Installation\n\nInstall the plugin from npm and import it into your bundle.\n\n```bash\nnpm install @swup/preload-plugin\n```\n\n```js\nimport SwupPreloadPlugin from '@swup/preload-plugin';\n```\n\nOr include the minified production file from a CDN:\n\n```html\n\u003cscript src=\"https://unpkg.com/@swup/preload-plugin@3\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\nTo run this plugin, include an instance in the swup options.\n\n```javascript\nconst swup = new Swup({\n  plugins: [new SwupPreloadPlugin()]\n});\n```\n\n## Preloading\n\nThe plugin supports four ways of preloading links:\n\n- Hovering a link\n- Marking links to preload with a special attribute\n- Watching the viewport for links to become visible\n- Passing in a list of URLs to preload at once\n\n### Hovering links\n\nHovering a link will automatically preload it. Enabled by default.\n\nDepending on the user's device, the preload will be triggered when it is hovered with a mouse,\ntouched with a finger, or focused using the keyboard. Hovered links are preloaded with higher\npriority than other running requests.\n\n```html\n\u003ca href=\"/about\"\u003eAbout\u003c/a\u003e \u003c!-- will preload when hovering --\u003e\n```\n\n### Marking links to preload\n\nTo preload specific links, mark them with the `data-swup-preload` attribute.\n\n```html\n\u003ca href=\"/about\" data-swup-preload\u003eAbout\u003c/a\u003e\n```\n\nTo preload all links in a container, mark the container with `data-swup-preload-all`.\n\n```html\n\u003cnav data-swup-preload-all\u003e\n  \u003ca href=\"/about\"\u003eAbout\u003c/a\u003e\n  \u003ca href=\"/contact\"\u003eContact\u003c/a\u003e\n\u003c/nav\u003e\n```\n\n### Preload links as they become visible\n\nPreload links as they enter the viewport. Not enabled by default.\n\nSee the [preloadVisibleLinks](#preloadvisiblelinks) option for details.\n\n### Preload a list of URLs\n\nPreload specific known URLs.\n\nSee the [swup.preload()](#preload) method for details.\n\n## Options\n\n### throttle\n\nType: `Number`, Default: `5`\n\nThe *concurrency limit* for simultaneous requests when preloading.\n\n### preloadHoveredLinks\n\nType: `Boolean`, Default: `true`\n\nPreload links when they are hovered, touched or focused.\n\n### preloadVisibleLinks\n\nType: `Boolean` | `Object`, Default: `false`\n\nPreload links when they enter the viewport. Pass in a boolean `true` to enable with default options.\n\n```js\nnew SwupPreloadPlugin({ preloadVisibleLinks: true })\n```\n\nFor more control over the behavior, pass in an object. These are the default options:\n\n```js\nnew SwupPreloadPlugin({\n  preloadVisibleLinks: {\n    /** How much area of a link must be visible to preload it: 0 to 1.0 */\n    threshold: 0.2,\n    /** How long a link must be visible to preload it, in milliseconds */\n    delay: 500,\n    /** Containers to look for links in */\n    containers: ['body'],\n    /** Callback for opting out selected elements from preloading */\n    ignore: (el) =\u003e false\n  }\n})\n```\n\n### preloadInitialPage\n\nType: `Boolean`, Default: `true`\n\nPreload the initial page to allow instant back-button navigation after having navigated away from\nit. Disable this if it causes issues or doesn't make sense in your specific scenario.\n\n## Methods on the swup instance\n\nThe plugin adds two methods for preloading pages to the swup instance.\n\n### preload\n\nPreload a URL or array of URLs. Returns a Promise that resolves when all requested pages have been preloaded.\n\n```js\nawait swup.preload('/path/to/page');\nawait swup.preload(['/some/page', '/other/page']);\n```\n\n### preloadLinks\n\nScan the DOM for links with the attribute `[data-swup-preload]` and call `preload` for each URL:\n\n```js\nswup.preloadLinks();\n```\n\n## Hooks\n\nThe plugin creates two new hooks.\n\n\u003e **Note** The visit object might be `undefined` or already settled for these hooks\n\n### page:preload\n\nFires when a page was preloaded.\n\n```js\nswup.hooks.on('page:preload', (_visit, { page }) =\u003e console.log('preloaded:', page));\n```\n\n### link:hover\n\nFires every time a link is hovered.\n\n```js\nswup.hooks.on('link:hover', (_visit, { el }) =\u003e console.log('link hovered:', el));\n```\n","funding_links":["https://github.com/sponsors/gmrchk","https://github.com/sponsors/daun","https://github.com/sponsors/hirasso","https://opencollective.com/swup"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswup%2Fpreload-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswup%2Fpreload-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswup%2Fpreload-plugin/lists"}