regex — эффективно минимизирует JavaScript с помощью переполнения стека

Привет всем, у меня есть функция Php, которые используют JSMin Сократить JavaScript, но я хочу заменить регулярное выражение
длинные аргументы имя с помощью а или б

function foo(long_arg_name, long_arg_name2){
alert(long_arg_name + long_arg_name);
}

в

function foo(a,b){
alert(a+b);
}

0

Решение

Вы можете использовать этот плагин:

https://github.com/promatik/PHP-JS-CSS-Minifier

Использует этот минификатор http://javascript-minifier.com/

Или используйте этот скрипт из
http://javascript-minifier.com/examples

<?php
// setup the URL, the JS and the form data
$url = 'http://javascript-minifier.com/raw';
$js = file_get_contents('./public/ready.js');
$data = array(
'input' => $js
);

// init the request, set some info, send it and finally close it
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$minified = curl_exec($ch);

curl_close($ch);

// output the $minified
echo $minified;
?>

Не забудьте все кешировать 🙂

0

Другие решения

Других решений пока нет …