aelvan/stamp
最新稳定版本:2.1.0
Composer 安装命令:
composer require aelvan/stamp
包简介
A simple plugin for adding timestamps to filenames.
README 文档
README
A tiny plugin for adding timestamp to filenames.
This is the Craft 3.x version of Stamp, for the Craft 2.x version see the master branch.
Requirements
This plugin requires Craft CMS 3.0.0 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project -
Then tell Composer to load the plugin:
composer require aelvan/stamp -
In the Control Panel, go to Settings → Plugins and click the “Install” button for Stamp.
Usage
Use it like this:
<script src="{{ craft.stamp.er('/assets/build/js/scripts.js') }}"></script>
Which results in:
<script src="/assets/build/js/scripts.1399647655.js"></script>
The er() method takes a second parameter for setting the format of the output. Possible values are file (default), folder, query and tsonly.
Example with folder:
<script src="{{ craft.stamp.er('/assets/build/js/scripts.js', 'folder') }}"></script>
Result:
<script src="/assets/build/js/1399647655/scripts.js"></script>
Example with query:
<script src="{{ craft.stamp.er('/assets/build/js/scripts.js', 'query') }}"></script>
Result:
<script src="/assets/build/js/scripts.js?ts=1399647655"></script>
Example with only:
Timestamp is: {{ craft.stamp.er('/assets/build/js/scripts.js', 'only') }}
Result:
Timestamp is: 1399647655
Hashing option
The craft.stamp.er() method takes a third parameter for setting the algorithm of the output. Possible values are ts (default), and hash.
ts stands for timestamp and behaves as shown above. hash gets the CRC32 checksum of the file instead of the timestamp. It's useful for cases when you need your cache busting to be fully deterministic.
For example:
<script src="{{ craft.stamp.er('/assets/build/js/scripts.js', 'file', 'hash') }}"></script>
Result:
<script src="/assets/build/js/scripts.2031312059.js"></script>
URL rewriting
For methods file and folder you probably want to do some url rewriting. Below are some examples of how this can be done,
adjust as needed for your server and project setup.
Apache:
# Rewrites asset versioning, ie styles.1399647655.css to styles.css.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d{10})\.(js|css)$ $1.$3 [L] # /assets/build/js/scripts.1399647655.js
# RewriteRule ^(.+)/(\d{10})/(.+)\.(js|css)$ $1/$3.$4 [L] # /assets/build/js/1399647655/scripts.js
nginx:
location @assetversioning {
rewrite ^(.+)\.[0-9]+\.(css|js)$ $1.$2 last; # /assets/build/js/scripts.1399647655.js
# rewrite ^(.+)/([0-9]+)/(.+)\.(js|css)$ $1/$3.$4 last; # /assets/build/js/1399647655/scripts.js
}
location ~* ^/assets/.*\.(?:css|js)$ {
try_files $uri @assetversioning;
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
Configuration
Stamp needs to know the public document root to know where your files are located. By default
Stamp will use @webroot, but on some server configurations this is not the correct
path. You can configure the path by creating a config file called stamp.php in your config folder,
and adding the publicRoot setting.
Example
'publicRoot' => '/path/to/website/public/',
Changelog
See CHANGELOG.md.
aelvan/stamp 适用场景与选型建议
aelvan/stamp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.11k 次下载、GitHub Stars 达 27, 最近一次更新时间为 2017 年 08 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「timestamp」 「Craft」 「craftcms」 「craft-plugin」 「asset-rev」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aelvan/stamp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aelvan/stamp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aelvan/stamp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Expand, collapse, change the status of, or delete multiple blocks in a Matrix field simultaneously.
Laravel Eloquent boolean & timestamp flagged attributes behavior.
Timestamp parameter in public file uri
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
统计信息
- 总下载量: 34.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 27
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-11