Skip to content

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

Notifications You must be signed in to change notification settings

evaldemar/yii-MultidomainClientScript

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Multidomain ClientScript (assets)

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

Preinstall

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,
    ),
    ...
)

Params

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

Examples

Example for indexedAssetsSubdomain = true param:

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

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

// will output:
    ...<script type="text/javascript" src="http://assets2.example.com/js/script.js"></script>
</body>

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%