Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I override the core jquery file with the externally hosted jquery from google

In Yii, currently all the dependancies for jquery are loading up a local version of jquery, which i believe is 1.6.*, un-minified.

Something along the lines of:

<script src="/assets/2343/js/jquery.js"></script>

I would like to update the core jquery dependancy to use the jquery 1.7.* from google

Basically I would like to include

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"> 

at the bottom of all my pages whenever jquery is a dependancy.

like image 594
Ben Rowe Avatar asked May 09 '12 11:05

Ben Rowe


2 Answers

After a bit more googling & looking around, I found the answer:

in the config, under 'components'

'clientScript'=>array(
  'packages'=>array(
    'jquery'=>array(
      'baseUrl'=>'http://ajax.googleapis.com/ajax/libs/jquery/',
        'js'=>array('1.7.2/jquery.min.js'),
      )
    ),
  ),
),
like image 72
Ben Rowe Avatar answered Nov 11 '22 09:11

Ben Rowe


There's also another method seen in yii's docs:

For example, we can include jquery.js from Google servers instead of our own server. To do so, we first configure the scriptMap as follows,

$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
 'jquery.js'=>false,
 'jquery.ajaxqueue.js'=>false,
 'jquery.metadata.js'=>false,
 ......
);

By mapping these script files to false, we prevent Yii from generating the code to include these files. Instead, we write the following code in our pages to explicitly include the script files from Google,

<head>
<?php echo CGoogleApi::init(); ?>

<?php echo CHtml::script(
 CGoogleApi::load('jquery','1.3.2') . "\n" .
 CGoogleApi::load('jquery.ajaxqueue.js') . "\n" .
 CGoogleApi::load('jquery.metadata.js')
 );
?>
......
</head>
like image 27
bool.dev Avatar answered Nov 11 '22 07:11

bool.dev