2

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.

  • this question is more about `Yii2 asset manager` rather than the duplicates mentioned above which are totally dependent on the browser settings @RiggsFolly – Muhammad Omer Aslam Jul 14 '18 at 15:42
  • 1
    @MuhammadOmerAslam Ok, I have re-opened the question. All yours to give an answer – RiggsFolly Jul 14 '18 at 15:43
  • 2
    @MuhammadOmerAslam Although in that case [this may be an obvious duplicate](https://stackoverflow.com/questions/28040018/how-do-i-disable-assets-caching-in-yii2) Alsong with lots of other things that pop out of google – RiggsFolly Jul 14 '18 at 15:46
  • yes maybe his issue is resolved by `forcecopy` or `appendTimestamp` option but he needs to add more code for that, @SuparnaDey please add the `Assetmanager` file that you are using to load the assets also add the `config` file for your app, it can be `config/web.php` if basic-app or `config/main.php` if advanced app – Muhammad Omer Aslam Jul 14 '18 at 15:55

1 Answers1

1

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.

rob006
  • 21,383
  • 5
  • 53
  • 74
  • :D i was about to write it but the thing is if the `assetManager` is using `$sourcePath` means outside web then he has to use `forceCopy` – Muhammad Omer Aslam Jul 14 '18 at 15:59
  • If `Ctrl` + `F5` solves the issue, then problem is only in browser cache. `appendTimestamp` should solve it. – rob006 Jul 14 '18 at 16:08