Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Google Fonts

Laravel Google Fonts Laravel Package

spatie/laravel-google-fonts

Self-host Google Fonts in Laravel with minimal setup: register Google Fonts embed URLs, then use the @googlefonts Blade directive. The package scrapes CSS, downloads and stores font assets locally, and renders CSS inline, falling back to Google links if anything fails.

View on GitHub
Deep Wiki
Context7

spatie/laravel-google-fonts makes self-hosting Google Fonts frictionless in Laravel. Register a Google Fonts embed URL in config/google-fonts.php, then render it with the @googlefonts Blade directive. On first request the package scrapes the CSS, downloads the assets from Google, stores them locally, and inlines the CSS—eliminating extra DNS lookups and third-party requests.

If anything goes wrong, it falls back to a <link> tag loading fonts from Google.

  • Config-driven font sets with named keys
  • @googlefonts Blade directive for clean layouts
  • Automatic local caching of CSS and font files
  • Safe fallback to remote Google Fonts
  • Artisan fetch command to pre-cache fonts
Frequently asked questions about Laravel Google Fonts
How do I install spatie/laravel-google-fonts in a Laravel app?
Install it with composer require spatie/laravel-google-fonts. Optionally publish the config file to define your font sets, then run php artisan storage:link so the cached font assets are publicly served. Finally add the @googlefonts directive to your layout's head section.
How does the @googlefonts Blade directive work?
You register one or more Google Fonts embed URLs in config/google-fonts.php under unique keys, then call @googlefonts or @googlefonts('key') in your Blade layout. On the first request the package scrapes the Google Fonts CSS, downloads the font binaries, stores them on a local disk, and rewrites the CSS to point at the local files. The resulting CSS is rendered inline in the head, so no request to Google is needed on subsequent page loads.
Which Laravel and PHP versions does this package support?
Laravel 9 through Laravel 13 are supported, and the maintainer has kept compatibility current with each major framework release. You need a PHP version supported by your Laravel release plus a writable filesystem disk. Because the directive sits in your render path, check the released constraints before upgrading Laravel.
Are fonts downloaded on every request, or only once?
Only once. Assets are fetched and cached the first time a font set is requested, and the cached CSS is rendered inline afterwards. For predictable deploys, run php artisan google-fonts:fetch in your deploy pipeline instead of relying on a production visitor to trigger the first fetch.
What happens if fetching or parsing Google Fonts fails?
The package falls back to a standard link tag pointing at Google's CDN, so your typography still renders. Note that the fallback flag defaults to ! env('APP_DEBUG'), which means production silently falls back while debug mode throws an exception. If privacy is the reason you self-host, monitor for that fallback firing.
Does it work with a strict Content Security Policy?
Yes. The package ships a nonce option that integrates with spatie/laravel-csp, so the inline style tag it renders can be allowed under a nonce-based CSP. Since the CSS is emitted inline rather than linked, a policy with no inline styles will block it unless you configure the nonce.
Can I store the self-hosted fonts on S3 or a CDN instead of the local disk?
Yes, the storage disk is configurable. Point it at an S3 or object-storage disk fronted by CloudFront or a similar CDN so multiple web nodes serve the same assets. If you use the default public disk, remember that each node needs its own copy unless the directory is shared.
Does it support legacy browsers such as IE11?
Not really, and the README says so. The package selects font formats using a hardcoded user-agent string, defaulting to Safari 14, which yields WOFF2-only coverage of roughly 95% or more of visitors. Supporting IE-era browsers is a product decision you should make explicitly rather than as an afterthought.
How do I keep self-hosted fonts updated when Google changes its CSS?
Re-run php artisan google-fonts:fetch on a schedule or on each deploy to pick up new font versions and asset URLs. Google's css2 endpoint is not a contracted API, so parsing can break when its output changes, and past releases have included fixes for exactly that. Assign someone to re-run the fetch and check the rendered head after any font-related issue.
When should I avoid this package and use an alternative?
It assumes server-rendered Blade output, so it fits Laravel monoliths and Blade-based apps cleanly. If your head is composed by a JS SPA, Inertia or Next.js front end, or a headless CMS driving several presentation layers, you would reimplement the fetch logic outside the directive and lose most of the value. In those cases self-host the files manually or use a dedicated font CDN instead.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections