doutenglou6588 2018-07-14 12:02 采纳率: 0%
浏览 79

使用php,JS强制浏览器在页面加载时使用最新的JS和CSS文件

I have developed some websites using custom PHP and YII2. Whenever I have modified any JS or CSS file, it doesn't give any effect on my web pages. To apply the newest version of my code, I have to press ctrl+f5 to refresh it.

I have already gone through the several answers, but no effect. I have checked the below links: Force browser to refresh css, javascript, etc
How can I force clients to refresh JavaScript files?

Please help me to solve this.

  • 写回答

1条回答 默认 最新

  • dongyou9818 2018-07-14 15:57
    关注

    You can achieve this by setting AssetManager::$appendTimestamp to true. In your web config:

    'assetManager' => [
        'appendTimestamp' => true,
    ]
    

    Whether to append a timestamp to the URL of every published asset. When this is true, the URL of a published asset may look like /path/to/asset?v=timestamp, where timestamp is the last modification time of the published asset file. You normally would want to set this property to true when you have enabled HTTP caching for assets, because it allows you to bust caching when the assets are updated.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向