jQuery loaded twice

Hello.

I have a problem with the optimization of the speed of my application.

I have ajaxLink which opens a dialog box using zii.widgets.jui.CJuiDialog.

Dialog box opens for about 5 seconds - it is much slower than for example on the site jquery.com.

Using firebug, I found that the problem is that jquery libraries loaded twice: when you open the dialgo box jquery and jquery.ui loaded again from the folder assets. They loaded with some numbers, like this:

jquery.js?=1304664973349 and jquery-ui.min.js?=1304664975489

Each library is loaded for about 2 seconds, so opening the window takes about 5 seconds.

There is any way to prevent the reloading of libraries?

I’m not pretty sure, but it looks like a bug. You should issue a ticket in a bug system, but I’m not sure if in Yii or in jQuery.

The moment of opening a dialog box is in my opinion entirely controlled by jQuery, not by PHP (and therefore Yii). Page is already generated at this stage, sent back to browser and browsers is responsible for executing any JavaScript code inside generated page (or referenced by it).

My shot would be that this is jQuery problem. Although I never run into issue of delay before opening a dialog box or jQuery being loaded twice. Can you upload somewhere a working example?

I think its because of Yii CJuiDialog class. It has init function, that has this code:


Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");

echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";

I think i must create new Dialog widget.

I already fix problem using scriptMap and CGoogleApi.

can you post your solution? thanks

In action try this:




$cs=Yii::app()->clientScript;

$cs->scriptMap=array(

   (YII_DEBUG ?  'jquery.js':'jquery.min.js')=>false,

);



Look at this: http://code.google.com/p/yii/issues/detail?id=2481

I can just ask the same question as markux, the other solutions didn’t really work for me …

… or maybe anyone else got a solution for loading jquery-ui.min.js twice in CJuiDialog?

Thanks in advance,

Mayjestic

If anyone is interested in my solution: I solved it like that:


Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;

I’m also preloading the files, so the modalbox just has to load about 5kb. (Instead of about 450kb before) … works great :slight_smile:

I am also having this same problem, 2 jquery.min.js files are being loaded one from google cdn and other one from assets, searched a lot, but coudn’t managed to find the source, can you please tell me where to put


Yii::app()->clientscript->scriptMap['jquery-ui.min.js'] = false;

this piece of code, so that its not loaded twice on every page.?

Since this is just a line of code, then you can put it virtually anywhere, for example, in your controller. But, if I’m not mistaken, you can also configure scriptMap directly in application configuration, just as you would do with other bulid-in application modules. Search the documentation and forum, this topic (or similar ones) where discussed a few times.

Not quite. This is the code that tells Yii to not to load bundled with it copy of jQuery. But you must provide your own by yourself. But, from your answer it seems that you’re already doing it, so – yes, it should stop jQuery from being loaded twice.

This solution should work, also for jui (with the correct filename).

If you are looking for a more generic solution for preventing double loaded script files in combination with ajax requests, try this extension: http://www.yiiframework.com/extension/nlsclientscript