
######
Loader
######


****
NAME
****


Kernel::System::Loader - CSS/JavaScript loader backend


***********
DESCRIPTION
***********


All valid functions.


****************
PUBLIC INTERFACE
****************


new()
=====


create an object


.. code-block:: perl

     my $LoaderObject = $Kernel::OM->Get('Kernel::System::Loader');



MinifyFiles()
=============


takes a list of files and returns a filename in the target directory
which holds the minified and concatenated content of the files.
Uses caching internally.


.. code-block:: perl

     my $TargetFilename = $LoaderObject->MinifyFiles(
         List  => [                          # optional,  minify list of files
             $Filename,
             $Filename2,
         ],
         Checksum             => '...',      # optional, pass a checksum for the minified file
         Content              => '...',      # optional, pass direct (already minified) content instead of a file list
         Type                 => 'CSS',      # CSS | JavaScript
         TargetDirectory      => $TargetDirectory,
         TargetFilenamePrefix => 'CommonCSS',    # optional, prefix for the target filename
     );



GetMinifiedFile()
=================


returns the minified contents of a given CSS or JavaScript file.
Uses caching internally.


.. code-block:: perl

     my $MinifiedCSS = $LoaderObject->GetMinifiedFile(
         Location => $Filename,
         Type     => 'CSS',      # CSS | JavaScript
     );


Warning: this function may cause a die() if there are errors in the file,
protect against that with eval().


MinifyCSS()
===========


returns a minified version of the given CSS Code


.. code-block:: perl

     my $MinifiedCSS = $LoaderObject->MinifyCSS( Code => $CSS );


Warning: this function may cause a die() if there are errors in the file,
protect against that with eval().


MinifyJavaScript()
==================


returns a minified version of the given JavaScript Code.


.. code-block:: perl

     my $MinifiedJS = $LoaderObject->MinifyJavaScript( Code => $JavaScript );


Warning: this function may cause a die() if there are errors in the file,
protect against that with eval().

This function internally uses the CPAN module \`\`JavaScript::Minifier\`\`.
As of version 1.05 of that module, there is an issue with regular expressions:

This will cause a die:


.. code-block:: perl

     function test(s) { return /\d{1,2}/.test(s); }


A workaround is to enclose the regular expression in parentheses:


.. code-block:: perl

     function test(s) { return (/\d{1,2}/).test(s); }



CacheGenerate()
===============


generates the loader cache files for all frontend modules.


.. code-block:: perl

     my %GeneratedFiles = $LoaderObject->CacheGenerate();



CacheDelete()
=============


deletes all the loader cache files.


.. code-block:: perl

     my @DeletedFiles = $LoaderObject->CacheDelete();


Returns a list of deleted files.


IsJavaScriptMinifierXSAvailable()
=================================


Tries to load JavaScript::Minifier::XS if available which provides faster creation of minified JavaScript.


.. code-block:: perl

     my $IsJavaScriptMinifierXSAvailable = $LoaderObject->IsJavaScriptMinifierXSAvailable();


Returns true value if JavaScript::Minifier::XS is available and loaded.


IsCSSMinifierXSAvailable()
==========================


Tries to load \`\`JavaScript::Minifier::XS\`\` if available which provides faster creation of minified JavaScript.


.. code-block:: perl

     my $IsCSSMinifierXSAvailable = $LoaderObject->IsCSSMinifierXSAvailable();


Returns true value if \`\`CSS::Minifier::XS\`\` is available and loaded.




