Skip to content

chore(prefetch): disable link prefetching on slow internet connections#15885

Open
Guanran928 wants to merge 1 commit into
sveltejs:mainfrom
Guanran928:slow-connection
Open

chore(prefetch): disable link prefetching on slow internet connections#15885
Guanran928 wants to merge 1 commit into
sveltejs:mainfrom
Guanran928:slow-connection

Conversation

@Guanran928
Copy link
Copy Markdown

@Guanran928 Guanran928 commented May 22, 2026

This PR disables link prefetching on slow Internet connections to avoid slowing down intentional page navigations network traffic.

Astro already does this: https://github.com/withastro/astro/blob/ace96ba5024129cbeb9d8e75134f4f8bdf42a57a/packages/astro/src/prefetch/index.ts#L303

You can test this by setting the network throttling to '3G' in Chrome. (it's weird, 3G shows up as '2g' in navigator.connection.effectiveType)

image

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 22, 2026

🦋 Changeset detected

Latest commit: db79bd9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// @ts-expect-error this isn't supported everywhere yet
if (!navigator.connection?.saveData) {
if (!navigator.connection?.saveData && !/2g/.test(navigator.connection?.effectiveType)) {
setup_preload();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something for the future: if the preload could be enabled/disabled (instead of just enabled once), we could use the change event on navigator.connection (docs) to toggle it dynamically (e.g. connection suddenly becomes slow or user switches to/from a WiFi hotspot from a mobile device).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants