Everytime I update my css or js files in infoweb\menu\module\assets, I have to empty the backend\web\assets folder
is there a way to automatically clear the assets cache?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I use
CClientScript::registerScriptFile
method in my view files:If I modified script.js, after next page reload I will see all changes
For css files -
CClientScript::registerCssFile
UPDATE: if you use yii 2.0 beta, you can read some information about changes in mechanic of client helpers here:
link
I configure the
assetManager::forceCopy=true
in main-local.php for the dev environment like thisThe AssetManager will create a hash based on the file modification time. The modification time of a directory does not change when any file is changed. If you have an AssetBundle that has a directory as
$sourcePath
, the modification time of the directory is used, the hash will not change, and nothing gets copied to theweb/assets
directory.I suggest overriding
AssetManager::hash()
in a subclass or write a function forAssetManager::$hashCallback
:For a sample implementation for finding the max modified date over all asset files in a bundle you could look at this comment by wookie @ http://php.net/manual/en/function.filemtime.php#35779
Note that modification to any asset file will create a new directory in
web/assets
, and regular cleanup will remain necessary. However, browser cache aside, refreshing the page will follow the latest changes.there is additional property as
to publish files even there are published before
Add this in your view:
Add this in your config:
Empty assets folder, and refresh, done
If you enviroment is production I recommend to use Cache Busting :
for more information about assets, read the Assets Yii2 documentation.