UNPKG

1.15 kBJavaScriptView Raw
1import { useShopConfig } from './useShopConfig';
2export function usePreconnectLinks({ ga = false, gtm = false } = {}) {
3 const { apolloConfig } = useShopConfig();
4 // These links are used with every store
5 const staticLinks = [
6 {
7 href: 'https://cdn.polyfill.io',
8 crossOrigin: null
9 },
10 (apolloConfig === null || apolloConfig === void 0 ? void 0 : apolloConfig.graphQLURI) && {
11 href: apolloConfig === null || apolloConfig === void 0 ? void 0 : apolloConfig.graphQLURI,
12 crossOrigin: null
13 }
14 ].filter(Boolean);
15 // Only preconnect to these urls if Google Analytics is enabled
16 const gaLinks = ga
17 ? [
18 'https://www.google-analytics.com',
19 'https://www.google.com',
20 'https://stats.g.doubleclick.net'
21 ]
22 : [];
23 // Only preconnect to these if GTM is enabled
24 const gtmLinks = gtm ? ['https://www.googletagmanager.com'] : [];
25 return [
26 ...staticLinks,
27 ...gaLinks.concat(gtmLinks).map(href => ({ href, crossOrigin: null }))
28 ];
29}
30//# sourceMappingURL=usePreconnectLinks.js.map
\No newline at end of file