You are here

function advagg_ext_minify_js_minify in Advanced CSS/JS Aggregation 8.2

Minify Javascript using via command line.

Parameters

string $contents: The JavaScript to minify.

1 string reference to 'advagg_ext_minify_js_minify'
advagg_ext_minify_advagg_js_minify_configuration_alter in advagg_ext_minify/advagg_ext_minify.module
Implements hook_advagg_js_minify_configuration_alter().

File

advagg_ext_minify/advagg_ext_minify.module, line 114
Advanced CSS/JS aggregation external minification module.

Code

function advagg_ext_minify_js_minify(&$contents) {
  $js_path = \Drupal::config('advagg.settings')
    ->get('root_dir_prefix') . 'advagg_js';
  $temp_file = \Drupal::service("file_system")
    ->tempnam($js_path, 'file_advagg_');
  $new_temp_file = $temp_file . '.js';
  rename($temp_file, $new_temp_file);
  $temp_file_full = advagg_get_relative_path($new_temp_file);
  file_put_contents($new_temp_file, $contents);
  $output = advagg_ext_minify_execute_cmd($temp_file_full, 'js');
  $contents = file_get_contents($output);

  // Cleanup.
  unset($new_temp_file);
  unset($temp_file_full);
  unset($output);
}