Hi I used your extension since ages to prevent reloading of js files (e.g. jquery) when adding/changing dynamic content on my application.
It has worked as a charm since i updated to yii 1.16 a few days ago.
As you might know with yii 1.16 a newer jquery and jquery.ui version are published.
The problem:
I have an ajax tab e.g. a jui widget which loads dynamically content from another action.
The content is e.g. a gridview, and because the page hasn't a gridview in the normal rendered content the gridview.js file should be loaded.
The ajax response has the correct request url, which is loaded when NLSClientScript isn't used as seen in the firebug console.
<script type="text/javascript" src="/yii/yii_app/assets/df55da87/gridview/jquery.yiigridview.js"></script>
But when I use NLSClientScript these not already loaded js files aren't dynamically requested.
I also find what causes the problem it is the usage of a beforeSend in an ajax
e.g. a simple link which does an ajax request and fill a div.
echo CHtml::ajaxLink(
'Test ajax request ',
Yii::app()->createUrl('test/ajaxresponse'),
array(
'type'=>'post',
'data'=> array(
Yii::app()->request->csrfTokenName=>Yii::app()->request->getCsrfToken(),
),
'update'=>'#ajaxresult_test',
'beforeSend'=>'js:function( jqXHR, settings ) {alert("beforeSend");return true;}',
)
);
echo CHtml::tag('div',array('id'=>'ajaxresult_test'), ' ');
the repsonse should be e.g. a renderpartial of a gridview (the normal rendered page should have a gridview so the gridview.js should be dynamically loaded.
$this->renderPartial('pages/gridview_test_ajax',array(),$return=false, $processOutput=true);
The gridview will be added to the page when i click the button. But it will get an javascript error
jQuery(...).yiiGridView is not a function which is correct because the function isn't available because it's not loaded.
It doesn't matter if the beforeSend is doing something or nothing. even a beforeSend:null would produce that error.
The problem also jquery.ui tabs is using a beforeSend function and therefore a $this->widget('zii.widgets.jui.CJuiTabs widget would produce the error.
If i don't set the beforeSend in the ajax link example the javascript files are loaded correctly.
If i use jquery <= 1.8.3 the beforeSend usage is also not a problem.
Only after usage of Jquery 1.9.0 and higher this error occurs.
I tested it in my yii application by trying different jquery versions.
'packages'=>array(
'jquery'=>array(
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8/',
'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.2/', // doesnt work
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.1/', // doesnt work
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.11.0/', // doesnt work
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.10.0/', // doesnt work
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/', // doesnt work
//'baseUrl'=>'//ajax.googleapis.com/ajax/libs/jquery/1.8.3/', // works!
'js'=>array('jquery.min.js'),
'coreScriptPosition'=>CClientScript::POS_HEAD
),
I don't know if NlsClientScript is really the problem because it works with ealier jquery versions, but because the js files are requested if the extension is not used I think that something is wrong.
I have tested with several versions of your extension seems that all are affected.
Can you look after this issue?
regards Horizons