承接 johannschopplich/kirby-hashed-assets 相关项目开发

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

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

johannschopplich/kirby-hashed-assets

Composer 安装命令:

composer require johannschopplich/kirby-hashed-assets

包简介

File name hashes support for css() and js() helpers

README 文档

README

Enhances Kirby's css() and js() helpers to support hashed filenames. Pass your normal paths (e.g. …main.js) – the plugin will lookup hashed assets and transform the path automatically (e.g. …main.20201226.js). That way you can even keep asset paths identical in development and production environment!

Key Features

  • 🛷 Cache bust assets without query strings
  • 🎢 No need for web server rewrite rules!
  • ⛸ Supports manifest.json
  • 🎿 Supports manually hashed file names
  • ☃️ Create preload links with hashedUrl() helper

Projects Using the Hashed Assets Plugin

Requirements

  • PHP 8.0+
  • Kirby 3.7+

Installation

Download

Download and copy this repository to /site/plugins/kirby-hashed-assets.

Git Submodule

git submodule add https://github.com/johannschopplich/kirby-hashed-assets.git site/plugins/kirby-hashed-assets

Composer

composer require johannschopplich/kirby-hashed-assets

Usage

Automatic Hashing With manifest.json

For file hashing this plugin uses the hashup npm package.

hashup is a tiny CLI tool with two objectives in mind for your freshly build assets:

  1. Rename or rather hash (hence the name) the assets.
  2. Generate a manifest.json for them.

You don't even have to install it to your devDependencies, since npx will fetch it once on the fly. Add hashup to your build pipeline by adding it your package.json scripts (recommended), for example:

{
  "scripts": {
    "clean": "rm -rf public/assets/{css,js}",
    "build": "npm run clean && <...> && npx -y hashup"
  }
}

Now, pass asset paths to Kirby's asset helpers like you normally do:

<?= js('assets/js/main.js') ?>
// `<script src="https://example.com/assets/js/main.9ad649fd.js"></script>

If a corresponding hashed file is found in the manifest.json, it will be used and rendered.

For template-specific assets, use @template (instead of @auto):

<?= js('@template') ?>
// `<script src="https://example.com/assets/js/templates/home.92c6b511.js"></script>`

Warning

If no template file exists, https://example.com/@template will be echoed. This will lead to HTTP errors and blocked content since the requested file doesn't exist and the error page's HTML will be returned.

If you are unsure if a template file exists, use the following helpers:

  • cssTpl()
  • jsTpl()

They will echo a link tag, respectively script tag, only if a template file for current page's template is present.

Manual Hashing

For smaller websites you may prefer no build chain at all, but still want to utilize some form of asset hashing. In this use-case you can rename your files manually.

Take an imaginary main.js for example. Just include it like you normally would in one of your snippets:

<?= js('assets/js/main.js') ?>

Now rename the file in the format of main.{hash}.js. You may use the current date, e.g.: main.20201226.js, which will output:

<script src="https://example.com/assets/js/main.20201226.js"></script>

Voilà, without changing the asset path the hashed file will be found and rendered in your template!

Hashed Filenames for Preloading Links

You can use the global hashedUrl() helper to lookup a file like you normally would with the css() or js() helpers. While the latter return a link or respectively script tag, the hashedUrl() helper will only return a URL which you can use in any context.

<link rel="preload" href="<?= hashedUrl('assets/css/templates/default.css') ?>" as="style">
// <link rel="preload" href="/assets/css/templates/default.1732900e.css" as="style">

Since all evergreen browsers finally support JavaScript modules natively, you may prefer preloading modules:

<link rel="modulepreload" href="<?= hashedUrl('assets/js/templates/home.js') ?>">
// <link rel="preload" href="/assets/js/templates/home.92c6b511.js">

License

MIT License © 2021-PRESENT Johann Schopplich

johannschopplich/kirby-hashed-assets 适用场景与选型建议

johannschopplich/kirby-hashed-assets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.61k 次下载、GitHub Stars 达 23, 最近一次更新时间为 2020 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「assets」 「helpers」 「css」 「JS」 「components」 「manifest」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 johannschopplich/kirby-hashed-assets 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.61k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-26