summaryrefslogtreecommitdiff
path: root/packages/integrations/prefetch/src
diff options
context:
space:
mode:
authorGravatar tony-sull <tony-sull@users.noreply.github.com> 2022-06-27 18:28:16 +0000
committerGravatar github-actions[bot] <github-actions[bot]@users.noreply.github.com> 2022-06-27 18:28:16 +0000
commitcb3fcdde6a1e37e82b672f962d75df2392628519 (patch)
treee29078c846dea4341fe00a6f988da06ce2cd16fe /packages/integrations/prefetch/src
parent79fe09fa3093eb8ac2871c1894b9cddf557aecba (diff)
downloadastro-cb3fcdde6a1e37e82b672f962d75df2392628519.tar.gz
astro-cb3fcdde6a1e37e82b672f962d75df2392628519.tar.zst
astro-cb3fcdde6a1e37e82b672f962d75df2392628519.zip
[ci] format
Diffstat (limited to 'packages/integrations/prefetch/src')
-rw-r--r--packages/integrations/prefetch/src/client.ts23
-rw-r--r--packages/integrations/prefetch/src/index.ts8
2 files changed, 18 insertions, 13 deletions
diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts
index 46a688f9d..9f951c8dd 100644
--- a/packages/integrations/prefetch/src/client.ts
+++ b/packages/integrations/prefetch/src/client.ts
@@ -66,24 +66,27 @@ export interface PrefetchOptions {
selector?: string;
/**
* The number of pages that can be prefetched concurrently.
- *
+ *
* @default 1
*/
throttle?: number;
}
-export default function prefetch({ selector = 'a[href][rel~="prefetch"]', throttle = 1 }: PrefetchOptions) {
+export default function prefetch({
+ selector = 'a[href][rel~="prefetch"]',
+ throttle = 1,
+}: PrefetchOptions) {
const conn = navigator.connection;
if (typeof conn !== 'undefined') {
- // Don't prefetch if using 2G or if Save-Data is enabled.
- if (conn.saveData) {
- return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled'));
- }
- if (/2g/.test(conn.effectiveType)) {
- return Promise.reject(new Error('Cannot prefetch, network conditions are poor'));
- }
- }
+ // Don't prefetch if using 2G or if Save-Data is enabled.
+ if (conn.saveData) {
+ return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled'));
+ }
+ if (/2g/.test(conn.effectiveType)) {
+ return Promise.reject(new Error('Cannot prefetch, network conditions are poor'));
+ }
+ }
const [toAdd, isDone] = throttles(throttle);
diff --git a/packages/integrations/prefetch/src/index.ts b/packages/integrations/prefetch/src/index.ts
index 15f52272c..a15f88747 100644
--- a/packages/integrations/prefetch/src/index.ts
+++ b/packages/integrations/prefetch/src/index.ts
@@ -9,9 +9,11 @@ export default function (options: PrefetchOptions = {}): AstroIntegration {
// Inject the necessary polyfills on every page (inlined for speed).
injectScript(
'page',
- `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(options)});`
+ `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(
+ options
+ )});`
);
- }
- }
+ },
+ },
};
}