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.
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
, wheretimestamp
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.