Skip to content


Subversion checkout URL

You can clone with
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (41 sloc) 1.99 kB

Multidomain ClientScript (assets)

Extending default Yii CClientScript class to use multiple subdomains for assets (scripts and stylesheets).


You should make sure, that your HTTP-server configured properly - 'assetsSubdomain' and all its combinations are pointing to your 'public_html' directory.

Install and config (available and default settings)

Place StaticClientScript.php file into protected/components directory. After this, you can enhance CClientScript class by making some changes in your config file (protected/config/main.php):

'components' => array(
    'clientScript' => array(
        'class' => 'application.components.MultidomainClientScript',
        'enableMultidomainAssets' => true,
        'assetsSubdomain' => 'assets',
        'indexedAssetsSubdomain' => false,


  • enableMultidomainAssets - whether to use subdomains for ClientScript assets. Default is true
  • assetsSubdomain - subdomain name (e.g. Default is 'assets'
  • indexedAssetsSubdomain - whether to use indexed subdomains for registered script files basing on their 'position' param. Default is false


Example for indexedAssetsSubdomain = true param:

Yii::app()->clientScript->registerScriptFile('/js/script.js', CClientScript::POS_HEAD)

// will output:
    <script type="text/javascript" src=""></script>
Yii::app()->clientScript->registerScriptFile('/js/script.js', CClientScript::POS_END)

// will output:
    ...<script type="text/javascript" src=""></script>
Jump to Line
Something went wrong with that request. Please try again.