I'm a Yii developer and I can tell you, that Yii has nothing to do with this. It is completely on developer side, whether he or she put Javascript code to a separate file and register it with HTML (view) page with CClientScript::registerScriptFile
method or put it directly to view (HTML) code and register it using CClientScript::registerScript
method.
As per your answer, most (professional?) Yii developers strongly vote for first approach, that is -- keeping as much Javascript code in separate files as possible. So, this is most certainly not a new trend of coding, but rather a bad developer practice. At least, that's how it is seen in Yii community.
EDIT: Actually, I forgot about most important argument. Yii (as well as most other professional PHP frameworks) is build upon MVC design pattern (actually: architectural pattern). And the same pattern can be used in fronted: HTML code is the model (data), CSS is the view (decorator) and Javascript is the controller. All of them put into separate files, .js
and .css
files -- minified, obsfucated and gzipped in the best scenario.
When you build up your Yii application, you can break the MVC pattern and keep everything in the same file. The question is -- is it worth doing so, what are the benefits (none?) and where will that lead you? You can use the same argumentation, when asking, whether to keep JS code inline or not?
<a onClick="function(){/* do stuff */} ">Click Here</a>
This, I understand, is considered VERY bad and one should seperate their code from their HTML See: This article