scriptMap won't work when debug mode is off

Hi guys,

What I want is to make Yii not to load its jquery.js from its assets because I need to load it myself.

So I just turn it off by using the following code and it works.




'components'=>array(

	'clientScript'=>array(

		'scriptMap'=>array(

			'jquery.js'=>false,

		),

	),

)



And when I finished the project and launch into server. I turn off debug mode by remove the following line from index.php as what was recommended in the script file.




defined('YII_DEBUG') or define('YII_DEBUG',true);



And this is what was happened Yii loaded jquery.js from its asset and made all jquery script broke.

And when I turned on the debug mode the script started to work again.

I wonder what is the connection of it I couldn’t find any clues. In addition I have more configuration in main.php more than I showed you guys but I’m not sure it will involve with this so I just show what I think it involves in.

Anyone has any idea?

Thanks in advance.

When YII_DEBUG is false, jquery.min.js will be included, not jquery.js. So just add it to your map.

Tell me Mike how do you track down the problems so fast? Where is that Yiidy (Jedy) school in Germany? Took me 10 minutes to track down… :)




$packages=array(

	'jquery'=>array(

		YII_DEBUG ? 'jquery.js' : 'jquery.min.js',

	),



Hehe, i had the same issue a couple of times, too. And like you ended up at packages.php.

And BTW i wouldn’t call a response time of 03:10 h fast … ;)

Experience makes the masters ;)

or should I say elites :D

The problem here is that zyphers missed one important point here… as he wrote:

So he even did not notice that it’s not jqeury.js that is included… but jquery.min.js…

OT:

I start to feel a bit lonely. Can someone finally also become a Elite Member, or what…? :D

Oh… Thanks everyone.

And yes mdomba you’re right I didn’t notice that. At first I thought it had the same meaning just to exclude jquery.js.

Those gallons aren’t easy to get buddy. But don’t worry, some try hard to get there… Nevertheless, is always good to have somebody to look at, even if it is a thinking monkey… :)

BTW: I think you should be promoted as you are also committer to the project. Those efforts should be rewarded.

Can I just comment out this code -

if I want the jquery.js to be loaded from the google api?

$packages=array(

    'jquery'=>array(


            YII_DEBUG ? 'jquery.js' : 'jquery.min.js',


    ),

You shouldn’t modify the framework file. Use the scriptMap property instead




'components'=>array(

  'clientScript'=>array(

    'scriptMap'=>array(

      'jquery.js'=>false,

    ),

  ),

)



Also read the API reference.

/Tommy

I would like to add that if you wish to add this:




'components'=>array(

  'clientScript'=>array(

    'scriptMap'=>array(

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

    ),

  ),

)



Also, if you use CGoogleAPI (just a note, I do not know if you do that), it is rendered after all the other javascript files (you could also set the CGoogleAPI to POS_HEAD and the rest on POS_END but that is not a solution). I suggest that you manually set the google API script on your view files. I had that issue with EGMap Extension.

I hope that will be solved in future releases, when they listen to a good friend of mine about weighting script files, so we could easily set the order of them.

Thanks for the reply - tri and antonio.

But both of the way does not work the js/jquery.min.js file in the browser’s view source.

// application components - still shows js/jquery.min.js in browser view source

'components'=>array(


	


   'clientScript'=>array(


            'coreScriptUrl'=>'js', // required to prevent asset publishing of core scripts


    	    'scriptMap'=>array(


				'jquery.js'=>false,


				'jquery.min.js'=>false,


    		 ),


        'enableJavaScript' => true,


     ),

// application components - still shows js/jquery.min.js in browser view source

'components'=>array(


	


   'clientScript'=>array(


            'coreScriptUrl'=>'js', // required to prevent asset publishing of core scripts


    	    'scriptMap'=>array(


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


    		 ),


        'enableJavaScript' => true,


     ),

Yes, I do use the CGoogleAPI in the view file after the ‘js’ file.

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


$cs->scriptMap=array(


    'jquery.ajaxqueue.js'=>false,


    'jquery.metadata.js'=>false,


    'jquery.yiiactiveform.js'=> Yii::app()->request->baseUrl. "/js/jquery.yiiactiveform.js" ,


);


$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/all.js'); 





echo CGoogleApi::init(); 





echo CHtml::script(


    CGoogleApi::load('jquery','1.4.4') . "\n".


    CGoogleApi::load('jqueryui','1.8.7') . "\n" 


);

Thanks

Rose

Rose, you must be missing something. I use exactly one of your setups and it works fine - no publishing of js core files anymore.

[color=#1C2837][size=2]


'clientScript'=>array(

  'coreScriptUrl'=>'dummy',

  'scriptMap'=>array(

    'jquery.js'=>false,

    'jquery.min.js'=>false,

  ),

),

[/size][/color]

Thank you Mike. It does work now.

I did following in the config/main.php


// application components


'components'=>array(


	


   'clientScript'=>array(


            'coreScriptUrl'=>'js', // required to prevent asset publishing of core scripts


    	    'scriptMap'=>array(


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


    	     ),


        'enableJavaScript' => true,


     ),

I did following in views/layouts/main.php


// For loading Jquery from google engine.


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


$cs->scriptMap=array(


    'jquery.ajaxqueue.js'=>false,


    'jquery.metadata.js'=>false,


    'jquery.yiiactiveform.js'=> Yii::app()->request->baseUrl. "/js/jquery.yiiactiveform.js" ,


	'jquery.min.js'=>false,


	'jquery.js'=>false,


);


$cs->registerScriptFile(Yii::app()->request->baseUrl.'/js/all.js'); 





echo CGoogleApi::init(); 





echo CHtml::script(


    CGoogleApi::load('jquery','1.4.4') . "\n".


    CGoogleApi::load('jqueryui','1.8.7') . "\n" 


);

ffs… thanks much for this, saved me a bit of debug time, but seems like something that the framework should be able to handle without having to do the detection – isn’t it going to affect almost everyone who does this?

OMG !

I wish I had seen this topic sooner, last night I didn’t sleep at all, and was working hard on my project, which I had to deliver today.

I finished it on 5:00 AM and just to feel better and being proud of myself, turned off Debug mode… now I wish i hadn’t !

You can guess what happened, in the morning I was going to present the project and BOOM! all scripts are broken, NOTHING works :expressionless:

was a really hard time :)) so embarrassing !

Now I see why… I think there should be some alerts somewhere to notify people about this tiny details which can make a project not working at all :)

thank you guys, at least now I feel better about my project, again!