Skip to content
Snippets Groups Projects

Allow grouping assets without preprocessing.

Files
2
@@ -155,24 +155,32 @@ public function deleteAll() {
@@ -155,24 +155,32 @@ public function deleteAll() {
public function optimizeGroup(array $group): string {
public function optimizeGroup(array $group): string {
$data = '';
$data = '';
$current_license = FALSE;
$current_license = FALSE;
foreach ($group['items'] as $js_asset) {
// Ensure license information is available as a comment after
// No preprocessing, single JS asset: just use the existing URI.
// optimization.
if ($group['type'] === 'file' && !$group['preprocess']) {
if ($js_asset['license'] !== $current_license) {
$data = file_get_contents($group['items'][0]['data']);
$data .= "/* @license " . $js_asset['license']['name'] . " " . $js_asset['license']['url'] . " */\n";
}
}
else {
$current_license = $js_asset['license'];
foreach ($group['items'] as $js_asset) {
// Optimize this JS file, but only if it's not yet minified.
// Ensure license information is available as a comment after
if (isset($js_asset['minified']) && $js_asset['minified']) {
// optimization.
$data .= file_get_contents($js_asset['data']);
if ($js_asset['license'] !== $current_license) {
}
$data .= "/* @license " . $js_asset['license']['name'] . " " . $js_asset['license']['url'] . " */\n";
else {
}
$data .= $this->optimizer->optimize($js_asset);
$current_license = $js_asset['license'];
 
// Optimize this JS file, but only if it's not yet minified.
 
if (isset($js_asset['minified']) && $js_asset['minified']) {
 
$data .= file_get_contents($js_asset['data']);
 
}
 
else {
 
$data .= $this->optimizer->optimize($js_asset);
 
}
 
// Append a ';' and a newline after each JS file to prevent them from
 
// running together.
 
$data .= ";\n";
}
}
// Append a ';' and a newline after each JS file to prevent them from
// running together.
$data .= ";\n";
}
}
 
// Remove unwanted JS code that causes issues.
// Remove unwanted JS code that causes issues.
return $this->optimizer->clean($data);
return $this->optimizer->clean($data);
}
}
Loading