Management of script downloads (e.g. "Ajax script downloads")
Posted 13 April 2012 - 11:52 AM
Posted 13 April 2012 - 03:51 PM
Posted 09 May 2012 - 01:04 PM
I use NLSClientScript in my projects and sometimes it's looks very useful.
I have page with several tabs, each tab should contain some widget. First tab is visible on page load, others can be activated by click and should load content via ajax. But with current Yii 1.1 I need to put contents of all tabs on initial page loading (inspite of fact that user sees only first tab and maybe never click on other). It's extra job for both server and client sides.
My suggestion for Yii2 is to extend CWidget with method to render assets only (something like renderAssets()). In this case all required js/css will be loaded without widget initialization itself.
Posted 10 May 2012 - 02:46 AM
within a widget, which isn't possible right now (a workaround would be to use $this->controller->renderPartial I think) but at the end of the day the problem is that as long as we are using a pure backend language to create the fancypants js/ajax stuff on the client side it will always be a tradeoff.
I am using this structure right now and I got used to it:
- js - controllers - post * create.js * view.js - comment * create.js * .... - protected - views - post * create.php
So if I render post/create I also register the script under js/controllers/post/create.js. It is more work, but at least you have full control over your client side code. I never use any ajaxXXX methods provided by Yii (except CActiveForm)
Posted 10 May 2012 - 07:27 AM
not exactly.. renderPartial within widget may be usefull, but I mean controller's renderPartial() with process output. I use this structure
but it requires NLSClientScript. Otherwise as already mentioned js will be processed twice.
I mean, for example, for CGridView I need yiigridview.js that located in some directory inside assets. I would like to call something like:
to add all required assets on page loading.
Afterwards I can render grid itself at any time via ajax on user request.