Yii Framework Forum: How Manage *.js/*.css Files Of External Extentions - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How Manage *.js/*.css Files Of External Extentions Rate Topic: -----

#1 User is offline   mstdmstd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 16-March 14

Posted 04 July 2014 - 09:53 AM

Hi,
In my yii 1.1.14 app I use some *.js/*.css files and I put them in header of layout, which is common for all app.
Also I use some external extentions and I see that these extentions set their own *.js/*.css files and they are put into the same layout and they are above my *.js/*.css files.
Seems that is not best way, as these extentions file are somethimes of lower versions then my files.

What is the tge best way of managing my own *.js/*.css files and files of external extentions ?

Also in source of page I see links like local-yii-tyb.com/tybapp/assets/995e17c6/jquery.js.
How can I define which external extention added this file ?

Thanks!
0

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 822
  • Joined: 02-July 10
  • Location:Central Poland

Posted 04 July 2014 - 10:00 AM

use CClientScript to manage scripts (js and css). you can configure mapping of scripts used by framework/components to your own files which should give you proper version across application.assets are hard to track, but this is rather simple - it is Yii jquery (added by some component using Yii::app()->clientScript->registerPackage( 'jquery' ); )

read more about mapping and clientscript:
http://www.yiiframew...-javascript-css
http://www.yiiframew...ng-script-files
http://www.yiiframew...1/CClientScript (especially param scriptMap)
red
0

#3 User is offline   mstdmstd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 16-March 14

Posted 05 July 2014 - 06:49 AM

Thank you, that was helpfull!
Also there is a question that in source of my page I see lines like:
<script type="text/javascript" src="/local-yii-tyb.com/tybapp/assets/995e17c6/jquery.js"></script>
<script type="text/javascript" src="/local-yii-tyb.com/tybapp/assets/995e17c6/jquery.yiiactiveform.js"></script>
<script type="text/javascript" src="/local-yii-tyb.com/tybapp/assets/mine/jquery/jquery-1.9.1.js"></script>

I think that first jquery.js was set by some extension.
And first jquery.js is of lower version of jquery-1.9.1.js which I use and I am afraid that in some cases that could raise problems.
What is the proper way to cope it ?
0

#4 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 822
  • Joined: 02-July 10
  • Location:Central Poland

Posted 07 July 2014 - 03:10 AM

use scriptMap and map jquery.js to your file location.

http://www.yiiframew...nstead-of-yiis/
red
0

#5 User is offline   mstdmstd 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 57
  • Joined: 16-March 14

Posted 08 July 2014 - 06:57 AM

Thank you for reply, but seems I still do not uderstand how to use scriptMap
In beforeAction action of my projects controll /protected/components/Controller.php I wrote like :

$cs = Yii::app()->clientScript;
$cs->registerPackage('jquery');
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery-1.9.1.js');
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery.yiiactiveform.js');
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery-ui-1.10.1.custom.js');

and in source of my page I see :
<script type="text/javascript" src="/local-yii-tyb.com/tybapp/assets/c0740966/jquery.js"></script> // Reference to lower version that I do
<script type="text/javascript" src="/local-yii-tyb.com/tybapp/assets/c0740966/jquery.yiiactiveform.js"></script>
<script type="text/javascript" src="http://localhost/local-yii-tyb.com/tybapp/assets/mine/jquery/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://localhost/local-yii-tyb.com/tybapp/assets/mine/jquery/jquery.yiiactiveform.js"></script> // jquery.yiiactiveform.js is included twice

I tried to write something like :
$cs = Yii::app()->clientScript;
$cs->registerPackage('jquery');
$cs->scriptMap = array(
	'jquery.js' => false,
'jquery.yiiactiveform.js' => false,
);
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery-1.9.1.js');
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery.yiiactiveform.js');
$cs->registerScriptFile($frontend_root_url . 'assets/mine/jquery/jquery-ui-1.10.1.custom.js');

But after that in console I get errors that jquery or yiiactiveform is not defined. What is the right way ?
0

#6 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 822
  • Joined: 02-July 10
  • Location:Central Poland

Posted 08 July 2014 - 08:59 AM

define scriptMap in config file. Put your jquery in [WWWROOT]/js/jquery-1.9.1.js

'components'=>array(
   ...
   'clientScript'=>array(
      ...
      'scriptMap'=>array(
         'jquery.js'=>'/js/jquery-1.9.1.js',
         'jquery.min.js'=>'/js/jquery-1.9.1.js',
      ),
      ...
   ),
...

of course you need $frontend_root_url defined. you may also map jquery.js -> false in config scriptMap and put your own jquery in template file but it must be loaded as first resource...
red
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users