MCPSERV.CLUB
google-webfonts-helper

google-webfonts-helper

Self-Hosted

Self-hosted Google Fonts with local fallback and performance optimization

Active(86)
12.7kstars
0views
Updated 13 days ago
google-webfonts-helper screenshot

Overview

Discover what makes google-webfonts-helper powerful

google‑webfonts‑helper is a lightweight, self‑hosted service that abstracts the complexity of downloading and serving Google Fonts locally. From a developer’s perspective, it offers a programmatic interface to fetch font families, generate CSS snippets, and cache the resulting assets on disk. The application runs as a single Node.js process, exposing both a web UI for manual font selection and an HTTP API that can be consumed by build tools or CI pipelines. Its core goal is to eliminate third‑party CDN dependencies while preserving the familiar Google Fonts API syntax, making it a drop‑in replacement for projects that require offline availability or stricter privacy compliance.

Font Retrieval API

Batch Download & Caching

Custom CSS Generation

Minimal Dependencies

Overview

google‑webfonts‑helper is a lightweight, self‑hosted service that abstracts the complexity of downloading and serving Google Fonts locally. From a developer’s perspective, it offers a programmatic interface to fetch font families, generate CSS snippets, and cache the resulting assets on disk. The application runs as a single Node.js process, exposing both a web UI for manual font selection and an HTTP API that can be consumed by build tools or CI pipelines. Its core goal is to eliminate third‑party CDN dependencies while preserving the familiar Google Fonts API syntax, making it a drop‑in replacement for projects that require offline availability or stricter privacy compliance.

Key Features

  • Font Retrieval API – Accepts standard Google Fonts query strings (family=Roboto:wght@400;700&display=swap) and returns a JSON payload containing URLs to the locally cached TTF/WOFF2 files, along with generated CSS @font-face rules.
  • Batch Download & Caching – Internally downloads requested font files, stores them in a configurable fonts/ directory, and serves subsequent requests from the local cache to reduce bandwidth.
  • Custom CSS Generation – Allows developers to specify subsets, weights, and display strategies; the API returns ready‑to‑use CSS that can be inlined or referenced via <link>.
  • Minimal Dependencies – Built with Express.js and a small set of utilities, keeping the runtime footprint low for containerized deployments.

Technical Stack

  • Runtime: Node.js (v18+), leveraging the event‑driven, non‑blocking I/O model for efficient HTTP handling.
  • Framework: Express.js for routing and middleware composition; templating is handled by Pug/EJS only for the optional UI.
  • Storage: The application persists font files on the local filesystem; no external database is required, which simplifies scaling to multiple instances behind a shared volume.
  • Packaging: The codebase is published as an NPM package, enabling integration into existing Node workflows (e.g., via npm run gwfh or as a child process).
  • Testing: Jest is used for unit tests, ensuring that font parsing and caching logic remains robust across updates.

Core Capabilities

  • RESTful API: GET /api/fonts?family=… returns JSON; POST /api/cache can pre‑populate the cache.
  • Webhooks: Optional webhook endpoints notify external services when a font is cached or updated.
  • Extensibility: The API can be wrapped in a custom middleware; developers may inject additional metadata (e.g., licensing info) into the response.
  • CLI Utility: A command‑line interface (gwfh download "Roboto:wght@400;700") allows scripting font pre‑fetching during build steps.

Deployment & Infrastructure

The application is intentionally lightweight, making it ideal for Docker or Podman containers. A typical deployment involves mounting a persistent volume to /app/fonts so that cached assets survive pod restarts. Because the service is stateless apart from the file cache, it scales horizontally by attaching multiple containers to a shared storage backend (NFS, S3‑compatible object store via s3fs, or Docker volumes). Health checks are available at /healthz, and the service exposes Prometheus metrics (/metrics) for observability. For high‑traffic scenarios, a reverse proxy (NGINX or Traefik) can be used to cache static font files at the edge, further reducing load on the Node process.

Integration & Extensibility

Developers can integrate google‑webfonts‑helper into their CI/CD pipelines by invoking the API from a build script, thereby ensuring that all fonts are bundled with the application artifacts. The service’s JSON response can be consumed by CSS preprocessors (Sass, Less) or bundlers (Webpack, Vite) to inject @font-face rules directly into the build output. Additionally, the optional webhook system enables automated cache invalidation when a new font version is released, keeping the local repository up to date without manual intervention.

Developer Experience

The configuration surface is minimal: a single config.json file for setting the base URL, cache directory, and optional authentication. Documentation is concise yet thorough, covering API usage, caching strategy, and deployment tips. The community around the project is active on GitHub; issues are triaged quickly, and pull requests for new features (e.g., support for variable fonts) are merged promptly. Licensing under MIT ensures that developers can use, modify, and redistribute the service without commercial restrictions.

Use Cases

  • Privacy‑First Websites – Replace third‑party Google CDN with a local copy to comply with GDPR or CCPA requirements.
  • Offline Development Environments – Fetch fonts once and serve them locally, eliminating network dependency during CI builds.
  • Custom Font Bundles – Generate a minimal CSS bundle containing only the required weights and subsets, reducing payload size.
  • Containerized Applications – Bundle fonts inside Docker images, ensuring consistent font rendering across environments.

Advantages

  • Performance – Local delivery eliminates DNS resolution and CDN latency, yielding faster font load times.
  • Control – Full ownership of the font files allows for custom optimization (e.g., subsetting, compression).
  • Simplicity – No external database or complex infrastructure; a single Node process and a shared volume suffice.
  • Flexibility – Works with any

Open SourceReady to get started?

Join the community and start self-hosting google-webfonts-helper today