承接 sylvainallignol/cache-stamp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sylvainallignol/cache-stamp

Composer 安装命令:

composer require sylvainallignol/cache-stamp

包简介

Cache buster for CSS, JS, fonts, SVG, PDF and images with advanced configuration options

README 文档

README

A simple and lightweight Kirby plugin to handle cache busting for CSS, JS, fonts, SVG, PDF and images with advanced configuration options.

Features

  • Automatic cache busting for CSS, JS, fonts, SVG, PDF and images
  • Multiple hash methods (MD5, SHA1, SHA256, XXH3, Timestamp)
  • Customizable hash prefix and suffix
  • Helpers and field methods
  • Supports both relative and absolute URLs

Requirements

  • Kirby CMS: 3x, 4.x, or 5.x
  • PHP 8.2 or superior

Installation

Via Composer (recommended)

composer require sylvainallignol/cache-stamp

Manual (ZIP)

  1. Download the latest release ZIP from GitHub
  2. Unzip into site/plugins/kirby-cache-stamp

Apache (.htaccess)

Add the following rules to the .htaccess file at the root of your site:

# --------------------------------------------------------
# Cache busting for CSS, JS, fonts, SVG, PDF and images
# --------------------------------------------------------

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.([a-zA-Z0-9]+)\.(css|js|woff2?|ttf|svg|pdf|jpe?g|png|gif|webp|avif)$ $1.$3 [L,NC]

Nginx (example)

location ~* ^/(.+)\.[a-zA-Z0-9]+\.(css|js|woff2?|ttf|svg|pdf|jpe?g|png|gif|webp|avif)$ {
    try_files /$1.$2 $uri =404;
}

Configuration

Add options to your config.php:

return [
    'sylvainallignol.cache-stamp' => [
        'active' => true,          // Enable/disable the plugin
        'method' => 'xxh3',        // Hash method: md5, sha1, sha256, xxh3, timestamp
        'prefix' => '',            // Prefix before the hash (a-z, A-Z, 0-9, -, _)
        'suffix' => ''             // Suffix after the hash (a-z, A-Z, 0-9, -, _)
    ]
];

Available Hash Methods

All hash methods use the file's modification timestamp as their source. The hash obscures the actual modification date for security reasons while still ensuring the URL changes when the file is updated.

  • xxh3 (default): Fast and efficient hash algorithm - produces a 16-character hash from the timestamp
  • md5: MD5 hash - produces a 32-character hash from the timestamp
  • sha1: SHA1 hash - produces a 40-character hash from the timestamp
  • sha256: SHA256 hash - produces a 64-character hash from the timestamp
  • timestamp: Direct file modification timestamp - uses the raw timestamp (not recommended for production as it exposes modification dates)

Note: If the file doesn't exist or its modification time cannot be determined, the plugin returns the original URL unchanged (no cache busting applied).

Supported File Types

The plugin automatically processes these file types:

  • css - Stylesheets
  • js - JavaScript files
  • woff, woff2 - Web fonts
  • ttf - TrueType fonts
  • svg - SVG files
  • pdf - PDF documents
  • jpg, jpeg - JPEG images
  • png - PNG images
  • gif - GIF images
  • webp - WebP images
  • avif - AVIF images

Usage

Automatic (Components)

The plugin automatically handles css() and js() helpers:

<?= css('assets/css/style.css') ?>
// Output: <link href="assets/css/style.a1b2c3d4.css" rel="stylesheet">

<?= js('assets/js/script.js') ?>
// Output: <script src="assets/js/script.e5f6g7h8.js"></script>

Helpers

Use the provided helper functions in your templates:

<?= cacheStamp('assets/css/style.css') ?>
// Output: assets/css/style.a1b2c3d4.css

<?= cacheStamp('assets/js/script.js') ?>
// Output: assets/js/script.e5f6g7h8.js

// Works with absolute URLs too (e.g., from asset()->url())
<?= cacheStamp(asset('images/logo.svg')->url()) ?>
// Output: https://yoursite.com/assets/images/logo.a1b2c3d4.svg

// Get only the hash
<?= cacheStampHash('assets/css/style.css') ?>
// Output: a1b2c3d4

Field Methods

Use cache stamp on field values when you store file paths in custom fields.

Useful when:

  • Users can configure custom stylesheets or scripts via the panel
  • You have flexible templates with dynamic asset loading
  • Custom icons, fonts, or documents are stored in text fields

Example blueprint:

fields:
  customStylesheet:
    type: text
    label: Custom Stylesheet
    placeholder: assets/css/custom.css
  brochurePdf:
    type: text
    label: Product Brochure
    placeholder: documents/brochure.pdf

Usage in templates:

// Custom stylesheet
<?php if ($url = $page->customStylesheet()->cacheStamp()): ?>
    <link href="<?= $url ?>" rel="stylesheet">
<?php endif ?>

// PDF download link
<?php if ($url = $page->brochurePdf()->cacheStamp()): ?>
    <a href="<?= $url ?>">Download brochure</a>
<?php endif ?>

Using the Class Directly

For advanced usage, you can use the CacheStamp class directly:

use Allignol\CacheStamp\CacheStamp;

$cacheStamp = new CacheStamp();

// Get stamped URL
$url = $cacheStamp->stamp('assets/css/style.css');

// Check if active
if ($cacheStamp->isActive()) {
    // ...
}

// Get current method
$method = $cacheStamp->method();

// Get all options
$options = $cacheStamp->options();

Example

// config.php
return [
    'sylvainallignol.cache-stamp' => [
        'method' => 'md5',
        'prefix' => 'v-',
        'suffix' => '-cached'
    ]
];

Output: style.v-d41d8cd98f00b204e9800998ecf8427e-cached.css

Notes

  • Absolute URLs remain absolute; relative URLs remain relative
  • URLs with query strings (?v=123) are ignored
  • Recommended for production: xxh3 or md5 for security & performance

Troubleshooting

  • No cache busting? Check that your rewrite rules are active and the plugin is enabled.
  • URL unchanged? The file may not exist or its extension is not supported.
  • Using query strings ? Those URLs are intentionally left untouched.

License

MIT

Credits

sylvainallignol/cache-stamp 适用场景与选型建议

sylvainallignol/cache-stamp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 139 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sylvainallignol/cache-stamp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sylvainallignol/cache-stamp 我们能提供哪些服务?
定制开发 / 二次开发

基于 sylvainallignol/cache-stamp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 139
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-12