PHP code example of istranger / yii2-resource-smart-load

1. Go to this page and download the library: Download istranger/yii2-resource-smart-load library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

istranger / yii2-resource-smart-load example snippets


'components' => [
    // ...
    'view' => [
        'class'           => 'istranger\rSmartLoad\View',
        'smartLoadConfig' => [
            // Hashing method for resource names (if string value),
            // see possible values: http://php.net/manual/en/function.hash.php#104987
            // Can be assigned "callable", for example: function ($str) { return hash('sha256', $str); }
            // 'hashMethod'               => 'md5', // default = 'crc32b'

            // Types of resources, that will be tracked by current extension
            // If =null,            // Disable native script filter 
            // (only for resource types specified in 'resourceTypes')
            // 'disableNativeScriptFilter' => false, // default = true
        ]
    ],
    // ...
],

    'enableLog' => true, // default = false

    array(
        RSmartLoad::RESOURCE_TYPE_JS_FILE,      // = 'jsFile'
        RSmartLoad::RESOURCE_TYPE_JS_INLINE,    // = 'jsInline'
        RSmartLoad::RESOURCE_TYPE_CSS_FILE,     // = 'cssFile'
        RSmartLoad::RESOURCE_TYPE_CSS_INLINE,   // = 'cssInline'
    )

    'alwaysReloadableResources' => ['bootstrap.js']  // default = []

Yii::$app->view->getRSmartLoad()->disableResources(['*'], [RSmartLoad::RESOURCE_TYPE_CSS_INLINE]);

if(Yii::$app->request->isAjax){
    Yii::$app->view->getRSmartLoad()->disableResources(['yii.gridView.js', 'bootstrap.css']);
}

Yii::$app->view->getRSmartLoad()->disableResources(['yii.gridView.js', 'bootstrap.css'],[
    RSmartLoad::RESOURCE_TYPE_CSS_INLINE,
    RSmartLoad::RESOURCE_TYPE_JS_FILE
]);

$view->getRSmartLoad()->disableLoadedResources(['*'], [
    RSmartLoad::RESOURCE_TYPE_JS_INLINE, 
    RSmartLoad::RESOURCE_TYPE_JS_FILE
]);

$view->getRSmartLoad()->disableLoadedResources(['*']);
 Yii::$app->view->getRSmartLoad()->disableLoadedResources(array $types = null); 
 Yii::$app->view->getRSmartLoad()->disableResources(array $resourceList, array $types = null); 
array('*')