cooltronicpl/craft-files-autoversioning 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

cooltronicpl/craft-files-autoversioning

最新稳定版本:2.2.0

Composer 安装命令:

composer require cooltronicpl/craft-files-autoversioning

包简介

A simple yet powerful Twig extension for CraftCMS. It assists in cache-busting your assets, ensuring that users always receive the latest versions of your files.

README 文档

README

This plugin is a Twig extension that helps you cache-bust your static assets, such as CSS, JS, images, videos, or PDFs. It appends a version number to the asset URL, based on either a build number or the file’s last modified time. This ensures that your users always receive the most recent version of your files, without having to clear their browser cache.

Static Files Autoversioning Plugin for Craft CMS

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Advanced Usage
  5. License
  6. Credits

Features

  • Compatible with Craft CMS 3.x, 4.x and 5.0.0.alpha
  • Supports multiple file types and caching policies
  • Allows custom versioning from strings or text files
  • Integrates with PDF Generator and Varnish Cache plugins

Installation

You can install this plugin from the Craft Plugin Store or with Composer.

From the Plugin Store

Go to the Plugin Store section of your Craft control panel and search for “Static Files Autoversioning”. Then click on the “Install” button in its modal window.

Project Setup

To install the plugin, navigate to your Craft project in your terminal:

# go to the project directory
cd /path/to/my-project

# tell Composer to load the plugin
composer require cooltronicpl/craft-files-autoversioning

# tell Craft to install the plugin
./craft install/plugin craft3-files-autoversioning

Usage

To use this plugin, you need to call the version() function in your template, passing the asset path as an argument. For example:

<link rel="stylesheet" href="{{ version('/css/styles.css') }}">

This will output something like:

<link rel="stylesheet" href="/css/styles.css?v=12345678" />

The version number (v=12345678) is determined by reading a file named build.txt in your root project folder (alongside config, templates, etc.). You can create and update this file using your deployment script. For instance, if you’re using CodeShip, you can use the following command:

echo -n "${CI_BUILD_NUMBER}" > build.txt

Advanced Usage

Versioning from a String

If you want to use a custom string as the version number, you can use the versionString() function, passing the asset path and the string as arguments. For example:

<link rel="stylesheet" href="{{ versionString('/css/styles.css', 'customstring') }}">

This will output something like:

<link rel="stylesheet" href="/css/styles.css?v=customstring">

Versioning from a Timestamp

If you want to use the file’s last modified time as the version number, regardless of the existence of the build.txt file, you can use the versionTimestamp() function, passing the asset path as an argument. For example:

<link rel="stylesheet" href="{{ versionTimestamp('/css/styles.css') }}">

This will output something like:

<link rel="stylesheet" href="/css/styles.css?v=1667385206">

Versioning from a Custom Text File

If you want to use the content of a custom text file as the version number, you can use the versionCustom() function, passing the asset path and the text file name as arguments. The text file should be located in your root project folder. For example:

<link rel="stylesheet" href="{{ versionCustom('/css/styles.css', 'mods.txt') }}">

This will output something like:

<link rel="stylesheet" href="/css/styles.css?v=modded">

Assuming that the mods.txt file contains the word “modded”.

Versioning with PDF Generator or Varnish Cache

You can also use this plugin with PDF Generator when your hosting or server is caching PDF files. Or your files are cached by caching plugins like Varnish Cache.

<a href="{{alias('@web')}}{{version("/" ~ craft.documentHelper.pdf('_pdf/document.twig', 'file', 'pdf/book'  ~ '.pdf'  ,entry, pdfOptions))}}">LINK</a>

This will output something like:

<a href="http://some-domain.com/pdf/book.pdf?v=1668157143">LINK</a>

This generates a PDF with a version number, solving any caching policy issues with your hosting.

Note about paths

By default, the plugin searches for files to version in the @webroot directory, and for the build.txt or custom text file in the @root path.

Note: You can learn more about the @webroot and @root aliases and how to configure them in the Craft CMS documentation.

License

This plugin is licensed under the GPLv3 license.

Credits

This plugin is brought to you with love by CoolTRONIC.pl sp. z o.o. (LLC) Interactive Agency and Pawel Potacki.

cooltronicpl/craft-files-autoversioning 适用场景与选型建议

cooltronicpl/craft-files-autoversioning 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 872 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「static-files-autoversioning」 「craft-cms-cache-busting-plugin」 「twig-extension-for-asset-versioning」 「craft-cms-static-asset-optimization」 「cache-busting-and-versioning-for-craft-cms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 cooltronicpl/craft-files-autoversioning 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2021-03-21