Weave Code
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 Package

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.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization: Reduces external dependencies by self-hosting Google Fonts, eliminating DNS lookups and third-party requests, improving Core Web Vitals (LCP, FID).
  • Privacy Compliance: Aligns with GDPR/CCPA by avoiding external tracking (Google Fonts’ analytics) and reducing third-party data collection.
  • Offline/Restricted Environments: Enables font loading in air-gapped systems, internal tools, or regions with restricted external access.
  • Brand Consistency: Ensures consistent typography across all pages, including offline or CDN-fallback scenarios.
  • Cost Efficiency: Eliminates potential bandwidth costs from repeated Google Font requests, especially for high-traffic sites.
  • Roadmap for Monolithic vs. Micro-Frontends: Simplifies font management in monolithic Laravel apps; can be extended to micro-frontend architectures with shared config.
  • Build vs. Buy: Buy—avoids reinventing wheel for font self-hosting, which would require significant dev effort (scraping, caching, CDN integration).
  • Use Cases:
    • Public-facing websites (e.g., blogs, e-commerce) needing faster load times.
    • Internal tools (e.g., dashboards) where external dependencies are discouraged.
    • Projects requiring strict compliance (e.g., healthcare, finance) with data residency laws.

When to Consider This Package

  • Look Elsewhere If:

    • Legacy Browser Support Needed: Package defaults to WOFF2 (unsupported in IE11). Requires manual user-agent tweaks for broader compatibility.
    • Dynamic Font Loading: Fonts must be loaded conditionally (e.g., based on user preferences). Package uses static config; dynamic logic would need custom extension.
    • Non-Laravel Stacks: Not applicable for non-PHP/Blade projects (e.g., React, Next.js, or static sites).
    • Existing Self-Hosting Setup: Already have a mature font self-hosting solution (e.g., custom script or CDN integration).
    • Minimalist Approach: Prefer zero-config solutions (e.g., keeping Google Fonts embedded for simplicity).
    • Font Customization Needs: Require real-time font generation or manipulation (e.g., variable fonts with runtime adjustments).
  • Adopt If:

    • Using Laravel 9+ and need a turnkey solution for self-hosted Google Fonts.
    • Prioritize performance (LCP improvements) and privacy (reducing third-party requests).
    • Willing to pre-fetch fonts during deployments (via google-fonts:fetch command) for zero-runtime overhead.
    • Font requirements are static (no runtime changes) and align with Google Fonts’ catalog.

How to Pitch It (Stakeholders)

For Executives:

"This package lets us self-host Google Fonts in Laravel, cutting external dependencies that slow down our site and expose users to third-party tracking. By caching fonts locally, we’ll see faster load times (improving SEO and conversions) and better compliance with privacy regulations—all with minimal dev effort. The upfront cost is negligible (MIT license, open-source), and the long-term savings in bandwidth and performance are significant, especially for high-traffic pages. It’s a no-brainer for our [performance/privacy/compliance] goals."

Key Metrics to Track:

  • Performance: 10–30% reduction in font-related requests (measured via Lighthouse or WebPageTest).
  • Privacy: Elimination of Google Fonts’ external requests (audit via Chrome DevTools’ Network tab).
  • Cost: Reduced bandwidth usage (monitor via hosting analytics).

For Engineering:

*"This package solves self-hosting Google Fonts with Laravel in three steps:

  1. Configure: Add embed URLs to config/google-fonts.php (e.g., Inter, IBM Plex Mono).
  2. Deploy: Run php artisan google-fonts:fetch to pre-download fonts to storage/app/public/fonts.
  3. Use: Load fonts in Blade with @googlefonts directives—it handles CSS inlining, preloading, and fallbacks automatically.

Why It’s Great for Us:

  • Zero Runtime Overhead: Fonts are fetched once during deployment (lazy-loading option in v1.6+).
  • CDN-Ready: Store fonts on any disk (e.g., S3) via Laravel’s filesystem.
  • CSP-Friendly: Supports nonces for Content Security Policy (works with spatie/laravel-csp).
  • Fallbacks: Gracefully degrades to Google’s CDN if local fetch fails (configurable).

Tradeoffs:

  • IE11 Unsupported: Defaults to WOFF2; add user_agent config tweak if needed.
  • Static Config: Fonts must be defined upfront; dynamic loading requires custom logic.

Next Steps:

  • Add to composer.json (spatie/laravel-google-fonts).
  • Configure fonts in config/google-fonts.php.
  • Run php artisan storage:link and google-fonts:fetch in CI/CD.
  • Test in staging to validate performance gains.

Alternatives Considered:

  • Manual self-hosting (too error-prone).
  • Keeping Google Fonts embedded (higher latency, privacy risks).
  • Custom script (reinventing the wheel).

Recommendation: Adopt. This is a battle-tested, low-maintenance solution for our Laravel stack."*

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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi