Cleaning Assets after Deploy

If you use assets for your js, css stuff in yii application, you have to re-publish it on deploy. And probably simplest way would be to delete everything under /path/to/public/www/assets. And we used to do that same way with YiiBoilerplate deployer for example. Although it isn't quite right solution:

  • If browser cached html page, the js/css tags in it still point to old directory which you deleted.
  • If you built heavy javascript application (or even single page application) which loads JS files on the fly, with require.js for example, it won't be able to find those deleted files after deploy until you refresh the page.

And you will have an errors like this in your log:

[error] [exception.CHttpException.404] exception
'CHttpException' with message 'Unable to resolve the request
"assets/c7d87fdd/js/libs/jquery/jquery.min.js".'

So, what's a solution? Best way to clean assets I found so far is to update modification time of assets directory with shell or php touch function, since CAssetManager::publish takes hash name based on path and path mtime.

Although you won't have such issues when you publish file, not directory, because modification time will be changed on content change. But modification time of directory won't be updated unless you added/deleted some files in there.

One more note: if you use some preprocessor like compass or r.js, don't forget to apply it before "touching" a directory that has to be published.

comments powered by Disqus
Made with in SPb