Shields.io (recommended for GitHub)
Shields.io badges are a reliable and consistent way to display dynamic data, such as hit counters, on platforms like GitHub. Below is an example of how to use a Shields.io badge:Key Features
- Caching: Updates approximately every 30 seconds due to Shields.io’s caching mechanism.
- Reliability: Works seamlessly across GitHub, npm, and other platforms.
- Consistency: Ideal for projects requiring stable and predictable badge behavior.
How to Use
- Copy the Markdown snippet above.
- Replace
id=homewith your unique counter ID. - Paste it into your README.md or any Markdown-supported file.
Direct SVG (live from nums)
Direct SVG badges fetch live data directly from your nums server. This method offers more customization options and faster updates. Here’s an example:Key Features
- Instant Updates: Reflects real-time data from your server.
- Customizable: Modify the badge’s appearance to match your project’s theme.
- GitHub Caching: Note that GitHub may cache the image for 1–2 minutes.
Customization Parameters
Below is a table of parameters you can use to customize your badge:| Param | Example | Description |
|---|---|---|
id | home | Unique key for your counter (page/project id) |
label | hits | Text shown on the left side of the badge |
style | terminal, mono | Badge style. Use terminal (monospace) or omit for classic. |
bg | #08c4fc | Background color (hex #rgb/#rrggbb or safe name) |
labelColor | #000000 | Label color (hex or safe name) |
valueColor | #ffffff | Value color (hex or safe name) |
font | ui-monospace | Font family for rendering |
Examples and guidance
-
id(string)- Example:
id=homeorid=downloads-page - Notes: IDs are arbitrary strings and are created on first /hit call. Use simple, URL-safe names (alphanumerics, dash, underscore).
- Example:
-
label(string)- Example:
label=hits,label=downloads,label=page%20views(space must be URL-encoded as%20) - Notes: Keep labels short (1–3 words) to avoid badge overflow.
- Example:
-
style(string)- Values: omit for the classic badge, or use
terminal/monofor the monospace terminal look. - Example (classic):
/badge?id=home&label=hits - Example (terminal):
/badge?id=home&style=terminal&label=hits
- Values: omit for the classic badge, or use
-
bg,labelColor,valueColor(colors)- Accepts hex (
#fff,#ffffff) or a small allowlist of color names (e.g.,blue,green,red). - IMPORTANT: When embedding in a URL, the
#must be URL-encoded as%23. - Example:
bg=%2308c4fc(renders#08c4fc) - Example terminal badge with custom colors (URL-encoded):
https://<deployment>/badge?id=home&style=terminal&bg=%23101414&labelColor=%23aaaaaa&valueColor=%233cffb3
- Fallback: invalid or unsupported colors fall back to safe defaults (server uses allowlist).
- Accepts hex (
-
font(string)- Example:
font=ui-monospace,font=Verdana,Geneva,DejaVu Sans,sans-serif - Notes: Provide a comma-separated font-family. When the chosen font isn’t available on the renderer, the browser/agent will use the next available fallback.
- Example:
Ready-to-copy examples
- Classic badge (blue):
- Terminal badge with custom colors (URL-encoded):
- Shields + nums (recommended for GitHub):
Rendering and caching notes
- GitHub and other hosts may cache badge images for 1–2 minutes even for direct SVGs; use the Shields approach for consistent ~30s caching.
- The terminal-style badge sets strong anti-cache headers to encourage revalidation, but proxies (like GitHub’s image proxy) may still cache.
How to Use
- Copy the Markdown snippet above.
- Replace
id=homewith your unique counter ID. - Adjust the parameters to customize the badge’s appearance.
- Paste it into your README.md or any Markdown-supported file.
Plaintext Badge
Plaintext badges are a simple and lightweight option for displaying hit counters in plain text format. These badges are ideal for environments where images are not supported or when you prefer a minimalistic approach.Example
Key Features
- Lightweight: No images, just plain text.
- Universal Compatibility: Works in any environment that supports text.
- Real-Time Updates: Fetches the latest counter value directly from the server.
How to Use
- Copy the plaintext URL above.
- Replace
id=homewith your unique counter ID. - Paste the URL into your desired location (e.g., README.md, plain text file, etc.).
- When accessed, the URL will display the current counter value as plain text.
Use Cases
- CLI Tools: Display hit counters in terminal-based applications.
- Text-Only Platforms: Ideal for environments that do not support images.
- Minimalistic Projects: Perfect for projects that prioritize simplicity and speed.
Quick Comparison
| Feature | Shields.io Badge | Direct SVG Badge |
|---|---|---|
| Update Speed | ~30 seconds | Instant (GitHub may cache ~1–2 min) |
| Reliability | High | Depends on server |
| Customization | Limited | Extensive |