'Yii2: Is there a Yii-way to force the browser reloading a CSS file?
Normally I would just do something like this:
<link href="main.css?<?= filemtime($file) ?>">
Is there a better way in Yii? – If not, is there a way I can add this to $this->head() for a specific CSS file?
Solution 1:[1]
If you are properly using asset bundles to load your styles you can set yii\web\AssetManager::$appendTimestamp property of asset manager component to append timestamp automatically.
You can do that in your app config file (for example frontend/config/main.php):
return [
'components' => [
'assetManager' => [
'appendTimestamp' => true,
],
],
// ... other configurations ...
]
See the guide article for more info about asset bundles.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michal HynÄica |
