Reputation: 241
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?
Upvotes: 0
Views: 485
Reputation: 6144
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.
Upvotes: 2