Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
//app/root.tsx
export function links() { return [ { rel: 'preconnect', href: 'http://fonts.googleapis.com', referrerPolicy: 'origin', }, { rel: 'preconnect', href: 'http://fonts.gstatic.com', crossOrigin: 'anonymous', referrerPolicy: 'origin', }, { rel: 'stylesheet', href: 'http://fonts.googleapis.com/css2?family=Quicksand:wght@300..700&display=swap', crossOrigin: 'anonymous', referrerPolicy: 'origin', }, {rel: 'stylesheet', href: tailwindCss}, {rel: 'stylesheet', href: resetStyles}, {rel: 'stylesheet', href: appStyles}, { rel: 'preconnect', href: 'https://cdn.shopify.com', }, { rel: 'preconnect', href: 'https://shop.app', }, {rel: 'icon', type: 'image/svg+xml', href: favicon}, ]; }
I am trying to fetch google fonts, where I add the google fonts links to function links() and set the Referral Policy to origin, but I am still having trouble fetching the google fonts.
Solved! Go to the solution
This is an accepted solution.
Hi @princessfiona,
To implement Google Fonts in Shopify Hydrogen, ensure your Content Security Policy (CSP) includes fonts.googleapis.com and fonts.gstatic.com in fontSrc and styleSrc directives. This resolves blocked requests caused by restrictive CSP settings. You can update your CSP using the createContentSecurityPolicy utility. Check Shopify’s documentation for details: CSP Guide.
Alternatively, for better performance and to avoid CSP updates, consider using the Fontsource library to self-host fonts. It eliminates the need to fetch fonts externally and improves load times. See an example in the Pilot Theme.
This is an accepted solution.
Hi @princessfiona,
To implement Google Fonts in Shopify Hydrogen, ensure your Content Security Policy (CSP) includes fonts.googleapis.com and fonts.gstatic.com in fontSrc and styleSrc directives. This resolves blocked requests caused by restrictive CSP settings. You can update your CSP using the createContentSecurityPolicy utility. Check Shopify’s documentation for details: CSP Guide.
Alternatively, for better performance and to avoid CSP updates, consider using the Fontsource library to self-host fonts. It eliminates the need to fetch fonts externally and improves load times. See an example in the Pilot Theme.