schnti/cachebuster

为 Kirby 3 CMS 添加修改时间戳的 CSS 和 JS 文件插件

1.0.3 2022-11-14 20:28 UTC

This package is auto-updated.

Last update: 2024-09-15 00:36:56 UTC


README

Kirby 3 CMS 提供的插件,可以将 CSS 和 JS 文件的修改时间戳添加到文件中,前提是它们通过 css() 和 js() 助手嵌入。

请注意,此插件不会向 CSS 和 JS 文件添加缓存头。要正确使用此插件,您需要将缓存规则添加到您的服务器配置中。

商业使用

此插件免费,但如果您在商业项目中使用它,请考虑以下事项:

安装

下载

下载文件 并将它们放置在 site/plugins/cachebuster 中。

Composer

composer require schnti/cachebuster

Git 子模块

您可以将插件作为 Git 子模块添加。

$ cd your/project/root
$ git submodule add https://github.com/schnti/kirby3-cachebuster.git site/plugins/cachebuster
$ git submodule update --init --recursive
$ git commit -am "Add Kirby Cachebuster plugin"

运行以下命令以更新插件

$ cd your/project/root
$ git submodule foreach git checkout master
$ git submodule foreach git pull
$ git commit -am "Update submodules"
$ git submodule update --init --recursive

选项

您可以使用以下行在您的 /site/config/config.php 中禁用插件:

return [
  'schnti.cachebuster.active' => true (default),
];

如何使用它

Apache 的 htaccess 规则

要使此插件在 Apache 上工作,您必须将以下行添加到您的 htaccess 文件中:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(js|css)$ $1.$3 [L]