Skip to content

Instantly share code, notes, and snippets.

@lusareal
Created March 23, 2023 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lusareal/8570e9d56407b27e788749265d4c7ab3 to your computer and use it in GitHub Desktop.
Save lusareal/8570e9d56407b27e788749265d4c7ab3 to your computer and use it in GitHub Desktop.
JavaScript minifier using toptal api
<?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