🐘

yii

1 notes  •  PHP & Web Dev

Fix Yii2 Asset Caching Issues in Development

In Yii2, the asset manager caches CSS/JS files. In development, stale assets can serve outdated files even after edits. Use one of these methods to disable caching.

Option 1 - Force Copy (Development Only)

In config/web.php:

'assetManager' => [
    'forceCopy' => true,  // Re-copies assets on every request
],

Only enable in development - significant overhead in production.

Option 2 - Symbolic Links (Recommended for Dev)

'assetManager' => [
    'linkAssets' => true,  // Symlinks instead of copies
],

File changes are immediately visible without clearing cache.

Option 3 - Clear Asset Cache Manually

rm -rf web/assets/*

Yii2 republishes assets on the next request.

Option 4 - Append Timestamp

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

Notes

  • Hard refresh the browser (Ctrl+Shift+R) to bypass browser cache as well.
  • In production, use asset bundling rather than forceCopy.