树莓派运行自助服务终端网站持续加载缓存旧视频问题求助
解决Firefox Kiosk模式下本地视频缓存不更新的问题
方案1:给视频URL添加随机时间戳(最直接有效)
浏览器缓存基于请求URL判定资源唯一性,只要URL带动态参数,就会触发重新加载。在设置视频源时追加当前时间戳,强制浏览器每次获取最新文件。
修改BodyOnLoad函数:
function BodyOnLoad() { var URL = location.href; var Extension = URL.split("?")[1]; // 追加时间戳参数 var timestamp = new Date().getTime(); var videoSrc = "/mnt/Drive_P/" + Extension + "?t=" + timestamp; window.setInterval(CheckVideoTimer, 10000); document.getElementById("VideoPlayerSourceMP4").src = videoSrc; document.getElementById("VideoPlayer").addEventListener('ended', VideoEnded, false); document.getElementById("VideoPlayer").load(); }
同时优化刷新逻辑,不用整页刷新,直接调用加载函数更高效:
function VideoEnded(e) { BodyOnLoad(); } function CheckVideoTimer() { var Vid = document.getElementById("VideoPlayer"); if ((Vid.paused && (Vid.duration == Vid.currentTime)) || (Vid.readyState == 0)) { BodyOnLoad(); } }
方案2:配置Firefox全局禁用缓存(适合终端固定场景)
针对Kiosk模式,直接修改Firefox缓存配置,从根源上避免缓存:
- 打开Firefox输入
about:config进入配置页 - 搜索并修改以下配置项:
browser.cache.disk.enable→ 设置为false(禁用磁盘缓存)browser.cache.memory.enable→ 设置为false(禁用内存缓存)browser.cache.offline.enable→ 设置为false(禁用离线缓存)
- 重启Firefox生效
如果需要通过自启动脚本加载预设配置,可指定自定义配置文件:
firefox --profile /path/to/custom-profile "file:///mnt/Drive_P/Kiosk/VideoViewer.html?Kiosk/Videos/Test.mp4" -kiosk -new-window
提前在自定义配置文件中完成上述缓存禁用设置。
方案3:替换视频源元素强制刷新
通过创建新的<source>元素替换旧元素,确保浏览器重新请求资源:
function reloadVideo() { var URL = location.href; var Extension = URL.split("?")[1]; var timestamp = new Date().getTime(); var videoSrc = "/mnt/Drive_P/" + Extension + "?t=" + timestamp; var videoPlayer = document.getElementById("VideoPlayer"); var oldSource = document.getElementById("VideoPlayerSourceMP4"); // 创建新source元素 var newSource = document.createElement("source"); newSource.id = "VideoPlayerSourceMP4"; newSource.src = videoSrc; newSource.type = "video/mp4"; // 替换旧元素并加载 videoPlayer.replaceChild(newSource, oldSource); videoPlayer.load(); }
需要刷新时调用reloadVideo()即可。
内容的提问来源于stack exchange,提问作者GuidoT
相关产品推荐
相关产品推荐

