spatie/laravel-google-fonts
Self-host Google Fonts in Laravel with minimal setup. Register Google Fonts CSS URLs in config and load them via the @googlefonts Blade directive. On first request it downloads CSS/assets, caches locally, inlines CSS, and falls back to Google if needed.
Pros:
config/google-fonts.php reduces technical debt.fallback setting).<link rel="preload"> (when enabled).spatie/laravel-csp.Cons:
google-fonts:fetch), which may introduce latency if not pre-fetched.@googlefonts and @googlefonts('font-name') integrate natively with Laravel views.php artisan google-fonts:fetch enables pre-fetching during deployment.storage:link for public asset serving.spatie/laravel-csp for nonce support.storage/app/public/fonts (or configured disk).APP_DEBUG=true to validate fallback behavior.php artisan cache:clear and google-fonts:fetch during deployments.Performance vs. Storage Tradeoff:
google-fonts:fetch) feasible during CI/CD, or should it be manual?Legacy Browser Support:
user_agent strings (e.g., IE11-compatible formats).Caching Strategy:
CDN/Edge Caching:
Monitoring:
Compliance:
Scalability:
@googlefonts directive fits seamlessly with Laravel’s templating.spatie/laravel-csp: For nonce-based CSP integration.Lighthouse scores before/after).composer require spatie/laravel-google-fonts
php artisan vendor:publish --provider="Spatie\GoogleFonts\GoogleFontsServiceProvider" --tag="google-fonts-config"
config/google-fonts.php with pilot fonts.php artisan google-fonts:fetch to pre-fetch assets.@import or <link> tags in Blade with @googlefonts.storage/app/public/fonts).google-fonts:fetch in deployment scripts.<!-- Before -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700" rel="stylesheet">
<!-- After -->
@googlefonts
<link> fallback.spatie/laravel-csp, update to include local font URLs:
// config/csp.php
'style-src' => [
"'self'",
"https://fonts.gstatic.com", // Fallback
Storage::disk('public')->url('fonts/inline.css'), // Local inlined CSS
],
user_agent (e.g., 'Mozilla/5.0 (compatible; MSIE 11.0; Windows NT 10.0; Trident/7.0)').storage/app/public is writable and linked:
php artisan storage:link
config/google-fonts.php.fallback to true during testing (false in production).@googlefonts in a non-critical view.preload for critical fonts.inline if external CSS is preferred (e.g., for cache control).php artisan google-fonts:fetch
storage/app/public/fonts growth (especially for large font libraries).config/google-fonts.php for new/removed fonts.How can I help you explore Laravel packages today?