Created
March 23, 2023 09:30
-
-
Save lusareal/8570e9d56407b27e788749265d4c7ab3 to your computer and use it in GitHub Desktop.
JavaScript minifier using toptal api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_POST['input'])) { | |
$input = $_POST['input']; | |
$url = 'https://www.toptal.com/developers/javascript-minifier/api/raw'; | |
// init the request, set various options, and send it | |
$ch = curl_init(); | |
curl_setopt_array($ch, [ | |
CURLOPT_URL => $url, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POST => true, | |
CURLOPT_HTTPHEADER => ["Content-Type: application/x-www-form-urlencoded"], | |
CURLOPT_POSTFIELDS => http_build_query(["input" => $input]) | |
]); | |
$minified = curl_exec($ch); | |
// finally, close the request | |
curl_close($ch); | |
// output the $minified JavaScript | |
echo '<textarea rows="55" cols="250">'.$minified.'</textarea>'; | |
}?> | |
<form action="" method="post"> | |
Input your javascript | |
<textarea autofocus="autofocus" rows="55" cols="250" name="input" id="input"></textarea> | |
<button type="submit">MINIFY</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment