Drupal 8  8.0.2
JsCollectionOptimizer Class Reference
Inheritance diagram for JsCollectionOptimizer:

Public Member Functions

 __construct (AssetCollectionGrouperInterface $grouper, AssetOptimizerInterface $optimizer, AssetDumperInterface $dumper, StateInterface $state)
 
 optimize (array $js_assets)
 
 getAll ()
 
 deleteAll ()
 

Protected Member Functions

 generateHash (array $js_group)
 

Protected Attributes

 $grouper
 
 $optimizer
 
 $dumper
 
 $state
 

Detailed Description

Optimizes JavaScript assets.

Constructor & Destructor Documentation

__construct ( AssetCollectionGrouperInterface  $grouper,
AssetOptimizerInterface  $optimizer,
AssetDumperInterface  $dumper,
StateInterface  $state 
)

Constructs a JsCollectionOptimizer.

Parameters
\Drupal\Core\Asset\AssetCollectionGrouperInterfaceThe grouper for JS assets.
\Drupal\Core\Asset\AssetOptimizerInterfaceThe optimizer for a single JS asset.
\Drupal\Core\Asset\AssetDumperInterfaceThe dumper for optimized JS assets.
\Drupal\Core\State\StateInterfaceThe state key/value store.

References Drupal\state().

Here is the call graph for this function:

Member Function Documentation

deleteAll ( )

{Deletes all optimized asset collections assets.}

Implements AssetCollectionOptimizerInterface.

References Drupal\config(), file_scan_directory(), file_unmanaged_delete(), and Drupal\state().

Here is the call graph for this function:

generateHash ( array  $js_group)
protected

Generate a hash for a given group of JavaScript assets.

Parameters
array$js_groupA group of JavaScript assets.
Returns
string A hash to uniquely identify the given group of JavaScript assets.

Referenced by JsCollectionOptimizer\optimize().

Here is the caller graph for this function:

getAll ( )

{Returns all optimized asset collections assets.

Returns
string[] URIs for all optimized asset collection assets.
}

Implements AssetCollectionOptimizerInterface.

References Drupal\state().

Here is the call graph for this function:

optimize ( array  $js_assets)

{Optimizes a collection of assets.

Parameters
array$assetsAn asset collection.
Returns
array An optimized asset collection.
}

The cache file name is retrieved on a page load via a lookup variable that contains an associative array. The array key is the hash of the names in $files while the value is the cache file name. The cache file is generated in two cases. First, if there is no file name value for the key, which will happen if a new file name has been added to $files or after the lookup variable is emptied to force a rebuild of the cache. Second, the cache file is generated if it is missing on disk. Old cache files are not deleted immediately when the lookup variable is emptied, but are deleted after a configurable period (

system.performance.stale_file_threshold

) to ensure that files referenced by a cached page will still be available.

Implements AssetCollectionOptimizerInterface.

References JsCollectionOptimizer\generateHash(), and Drupal\state().

Here is the call graph for this function:


The documentation for this class was generated from the following file: