pdfjs升级版本后出现 Message: The API version “4.6.82“ does not match the Worker version “4.5.136“,缓存版本没有刷新问

1 篇文章 0 订阅

1.升级pdf.js版本后, 由于客户之前浏览器上还缓存着旧的js,所以导致打开pdf出现错误

Message: The API version "4.6.82" does not match the Worker version "4.5.136"

2.通过html,js页面清理缓存没有效果

3.不方便让每个客户去手动清理浏览器缓存,也不方便直接修改后台跳转pdf.js代码

4.直接复制一个新版本pdf.js,取名为pdf.jsnew, 然后把旧的pdf.js跳转到pdf.jsnew

修改 viewer.html

<script>
  function redirectWithCurrentQueryParams(targetUrl) {
    // 解析当前URL的查询参数
    const currentQueryParams = new URLSearchParams(window.location.search);
    let targetQueryParams = new URLSearchParams(targetUrl.split('?')[1] || '');
    // 将当前URL的查询参数添加到目标URL
    for (const [key, value] of currentQueryParams.entries()) {
      targetQueryParams.set(key, value);
    }
    // 重定向到新的URL
    window.location.href = targetUrl + '?' + targetQueryParams.toString();
  }
  // 重定向到新的URL  解决客户浏览器缓存旧版本问题
  redirectWithCurrentQueryParams('/项目访问路径/PDF.jsnew/web/viewer.html');
</script>

  • 6
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值