diff options
author | 2023-07-07 16:01:23 -0400 | |
---|---|---|
committer | 2023-07-07 16:01:23 -0400 | |
commit | 9807e4dc22355f0b3b2ff65b0724a95af8e9702d (patch) | |
tree | 723c86670761f97a1bc7b89141521a740e37aff8 /packages/integrations/prefetch/README.md | |
parent | c135633bf6a84e751249920cba9009f0e394e29a (diff) | |
download | astro-9807e4dc22355f0b3b2ff65b0724a95af8e9702d.tar.gz astro-9807e4dc22355f0b3b2ff65b0724a95af8e9702d.tar.zst astro-9807e4dc22355f0b3b2ff65b0724a95af8e9702d.zip |
Updates prefetch integration to add "only prefetch link on hover/mouseover/focus" option (#6585)
* modifies prefetch to add the option to only prefetch certain pages on hover
* adds new pages to the test website to showcase prefetch-intent functionality
* adds tests to verify prefetch-intent behavior
* adds changelog
* waits until networkidle to check if the prefetching worked instead of waiting on a specific url load
* allows intentSelector to be either a string or array of strings
* Revert "allows intentSelector to be either a string or array of strings"
This reverts commit b0268eb0d5220ad2b08b0b7aee23f43e4caf879f.
* fixes the multiple selector logic and adds tests
* updates docs to include new prefetch-intent integration
* Update packages/integrations/prefetch/README.md
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update packages/integrations/prefetch/README.md
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update packages/integrations/prefetch/README.md
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update .changeset/little-cars-exist.md
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
* Update packages/integrations/prefetch/README.md
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
---------
Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Diffstat (limited to 'packages/integrations/prefetch/README.md')
-rw-r--r-- | packages/integrations/prefetch/README.md | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/integrations/prefetch/README.md b/packages/integrations/prefetch/README.md index 4dab2121b..9a061fc2a 100644 --- a/packages/integrations/prefetch/README.md +++ b/packages/integrations/prefetch/README.md @@ -56,6 +56,8 @@ export default defineConfig({ When you install the integration, the prefetch script is automatically added to every page in the project. Just add `rel="prefetch"` to any `<a />` links on your page and you're ready to go! +In addition, you can add `rel="prefetch-intent"` to any `<a />` links on your page to prefetch them only when they are hovered over, touched, or focused. This is especially useful to conserve data usage when viewing your site. + ## Configuration The Astro Prefetch integration handles which links on the site are prefetched and it has its own options. Change these in the `astro.config.mjs` file which is where your project's integration settings live. @@ -80,6 +82,28 @@ export default defineConfig({ }); ``` +### config.intentSelector + +By default, the prefetch script also searches the page for any links that include a `rel="prefetch-intent"` attribute, ex: `<a rel="prefetch-intent" />`. This behavior can be changed in your `astro.config.*` file to use a custom query selector when finding prefetch-intent links. + +__`astro.config.mjs`__ + +```js +import { defineConfig } from 'astro/config'; +import prefetch from '@astrojs/prefetch'; + +export default defineConfig({ + // ... + integrations: [prefetch({ + // Only prefetch links with an href that begins with `/products` or `/coupons` + intentSelector: ["a[href^='/products']", "a[href^='/coupons']"] + + // Use a string to prefetch a single selector + // intentSelector: "a[href^='/products']" + })], +}); +``` + ### config.throttle By default the prefetch script will only prefetch one link at a time. This behavior can be changed in your `astro.config.*` file to increase the limit for concurrent downloads. |