Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not fallback to XHR? #12

Open
moory-se opened this issue Jan 21, 2022 · 0 comments
Open

Does not fallback to XHR? #12

moory-se opened this issue Jan 21, 2022 · 0 comments

Comments

@moory-se
Copy link

Hi,

Reading the code, I fail to find where it actually "fallbacks to XHR".

  // Prefetch the given url using native 'prefetch'. Fallback to 'xhr' if not supported
  const prefetch = (url) =>
    new Promise((resolve, reject) => {
      const link = document.createElement(`link`);
      link.rel = `prefetch`;
      link.href = url;
      link.onload = resolve;
      link.onerror = reject;
      document.head.appendChild(link);
    });

It does not seem to be a fallback mechanism built in here.

This code is, if I read it correctly, in fact not even running since we stop execution on line 21 if prefetch is not supported:

  // Don't start prefetching if user is on a slow connection or not supported
  if (isSlowConnection || !isSupported) return;

Am I missing something? If not, I'll happily make a PR that actually implements XHR. I guess this be very inspired by how Quicklink does it.

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

No branches or pull requests

1 participant