Loader#
NAME#
Kernel::System::Loader - CSS/JavaScript loader backend
DESCRIPTION#
All valid functions.
PUBLIC INTERFACE#
new()#
create an object
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.
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.
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
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.
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:
function test(s) { return /\d{1,2}/.test(s); }
A workaround is to enclose the regular expression in parentheses:
function test(s) { return (/\d{1,2}/).test(s); }
CacheGenerate()#
generates the loader cache files for all frontend modules.
my %GeneratedFiles = $LoaderObject->CacheGenerate();
CacheDelete()#
deletes all the loader cache files.
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.
my $IsJavaScriptMinifierXSAvailable = $LoaderObject->IsJavaScriptMinifierXSAvailable();
Returns true value if JavaScript::Minifier::XS is available and loaded.
IsCSSMinifierXSAvailable()#
Tries to load CSS::Minifier::XS if available which provides faster creation of minified CSS.
my $IsCSSMinifierXSAvailable = $LoaderObject->IsCSSMinifierXSAvailable();
Returns true value if CSS::Minifier::XS is available and loaded.