github GoogleChromeLabs/quicklink 1.0.0
Quicklink 1.0.0

latest releases: 2.3.0, 2.2.0, 2.1.0...
5 years ago

Quicklink attempts to make navigations to subsequent pages load faster by prefetching in-viewport links during idle time

A huge thanks to everyone that has been trying out quicklink, sharing feedback and deploying it to production (like Hashnode and CleverTogether). We're glad you found our micro-library helpful. We've just published a new version to address early feature requests 🗣

New features 🎉

Control what domains can be prefetched 🏘

We now support origins: a new static array of URL hostname strings that are allowed to be prefetched. Defaults to the same domain origin, which prevents any cross-origin requests. This was a requested change in behavior from earlier versions of quicklink which would fetch all origins by default.

You can use origins as follows:

Specify a custom list of allowed origins

Provide a list of hostnames that should be prefetch-able. Only the same origin is allowed by default.

Important: You must also include your own hostname!

quicklink({
  origins: [
    // add mine
    'my-website.com',
    'api.my-website.com',
    // add third-parties
    'other-website.com',
    'example.com',
    // ...
  ]
});

Allow all origins

Enables all cross-origin requests to be made.

Note: You may run into CORB and CORS issues!

quicklink({
  origins: true
});

Control what URLs are ignored by RegExp, Function or Array ✋

We also now support ignores which adds support for filtering. This can be a RegExp, Function, or Array that further determines if a URL should be prefetched. These filters run after the origins matching has run.

Ignores can be useful for avoiding large file downloads or for responding to DOM attributes dynamically.

// Same-origin restraint is enabled by default.
//
// This example will ignore all requests to:
//  - all "/api/*" pathnames
//  - all ".zip" extensions
//  - all <a> tags with "noprefetch" attribute
//
quicklink({
  ignores: [
    /\/api\/?/,
    uri => uri.includes('.zip'),
    (uri, elem) => elem.hasAttribute('noprefetch')
  ]
});

If you tried out the first release of quicklink and noticed it prefetching /logout pages, download links or any other resources you'd rather it not, this new feature should help.

Bug fixes

This release also includes a few bug-fixes. These include URLs being prefetched are now also normalized by default (https://www.google.com vs. https://www.google.com/ vs https:\\www.google.com/). Thanks to @mathiasbynens for bringing this to our attention.

See API docs and recipes for details on how to use these new features. You can also find a new FAQ for answers to common questions we've had users ask about the project.

Size check 📦

Bundle size: 782 bytes minified & gzipped. We were able to introduce new features while keeping our size down in large part thanks to clever code-golfing by @lukeed ⛳️

Thanks 😍

With huge thanks to @lukeed and our lovely contributors for all of their help with this release ❤️We couldn't have done it without you!.

Full release notes

Don't miss a new quicklink release

NewReleases is sending notifications on new releases.