Giter VIP home page Giter VIP logo

yii-multidomainclientscript's Introduction

Multidomain ClientScript (assets)

A modified version of the excellent Yii extension by Borales. The modifications include:

  • Add declaration of member variable '$enableStaticAssets', which was referenced but never defined
  • Add code in function getAssetsBaseUrl to strip other subdomains from request url.

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',
        'subdomainsToRemove' => false,
        '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'
  • subdomainsToRemove - array of subdomain names to strip from request url before prepending 'assetsSubdomain' (e.g. array('admin','api')). Default is false, or no subdomains.
  • 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>

yii-multidomainclientscript's People

Contributors

borales avatar garyburge avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.