fix: gif-player 加 cache-bust 击穿微信 GET 缓存

- config.js 新增 MEDIA_CACHE_BUST 常量,换媒体后改此值即可强制客户端重下
- gif-player _load 给 src 追加 cb 参数,避免覆盖 720 动图后仍显示微信缓存的旧 180 图
This commit is contained in:
2026-07-24 16:31:12 +08:00
parent 393157e56b
commit 8d584129ec
2 changed files with 12 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
// gif-player微信 <image> 组件不播放 GIF 动画(只渲染首帧),
// 这里用 Canvas 2D + 纯 JS 解码器(omggif)逐帧绘制,实现真正的动图播放。
const { GifReader } = require('../../utils/vendor/omggif.js');
const config = require('../../config.js');
Component({
properties: {
@@ -41,9 +42,13 @@ Component({
if (this._timer) { clearTimeout(this._timer); this._timer = null; }
},
_load() {
const src = this.data.src;
if (!src || this._aborted) return;
// 同一 src 且已解码完成则跳过,避免 attached 与 observer 重复触发
const raw = this.data.src;
if (!raw || this._aborted) return;
// 击穿微信 GET 缓存:服务器静态文件被覆盖新版本(如重做超分动图)后,
// 旧图仍可能被微信请求缓存导致客户端显示旧图。加固定 bust 参数强制重新下载。
const sep = raw.indexOf('?') >= 0 ? '&' : '?';
const src = raw + sep + 'cb=' + config.MEDIA_CACHE_BUST;
// 同一 src(含 bust)且已解码完成则跳过,避免 attached 与 observer 重复触发
if (this._loadedSrc === src && this._reader) return;
this._loadedSrc = src;
this._clearTimer();

View File

@@ -3,5 +3,8 @@
// 中配置的 HTTPS 合法域名request 合法域名),否则真机无法发起请求。
// 当前直连服务器 IP开发期在微信开发者工具中勾选「不校验合法域名」即可联调
module.exports = {
BASE_URL: 'http://192.227.237.8:3001'
BASE_URL: 'http://192.227.237.8:3001',
// 媒体资源缓存击穿:服务器静态文件(动图/图片)被覆盖新版本后,旧版可能被微信请求缓存,
// 导致客户端仍显示旧图。换媒体(如重做超分动图)后修改此值即可强制全量客户端重新下载。
MEDIA_CACHE_BUST: '20260724'
};