Minifying HTML from an input string or urls.
.Maui HTML Minify API for minifying HTML documents from an input string or urls.
POSTGET *https://api.dotmaui.com/client/1.1/htmlmin/
Parameters
| Field | Type | Description | Required |
|---|---|---|---|
| apikey | String |
.Maui Api key |
True |
| html | String |
HTML code |
1 |
| url | String |
Valid URL to a web page |
1 |
| collapseboolattr | Boolean |
Remove attribute values from boolean attributes. Default is false |
False |
| collapsewhitespace | String |
Possible values:
|
False |
| decodeentities | Boolean |
Use Unicode characters (whenever possible). Default is false |
False |
| keepclosingslash | Boolean |
Keep the trailing slash on singleton elements. Default is false |
False |
| maxlinelength | Integer |
Maximum line length (output will be split by newlines at valid HTML split-points). Default is 999 |
False |
| minifycss | Boolean |
Minify CSS. Default is true |
False |
| minifyjs | Boolean |
Minify Javascript. Default is true |
False |
| removeattributequotes | Boolean |
Remove quotes around attributes when possible. Default is false |
False |
| removecomments | Boolean |
Strip HTML comments. Default is false |
False |
| removeemptyattributes | Boolean |
Remove all attributes with whitespace-only values. Default is false |
False |
Success 200
It will be a string with the HTML code minimized
HTTP/1.1 200 OK <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
Examples
import urllib.parse
import urllib.request
html_string = """
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
"""
params = urllib.parse.urlencode({'apikey': 'YOUR_API_KEY', 'html': html_string, 'collapsewhitespace': 'all'}).encode("utf-8")
minified = urllib.request.urlopen("https://api.dotmaui.com/client/1.1/htmlmin/", data = params).read().decode("utf-8")
print(minified)
# Output:
#<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>
<?php
$data = array('apikey' => 'YOUR_API_KEY',
'collapsewhitespace' => 'no',
'keepclosingslash' => 'true',
'minifycss' => 'false',
'minifyjs' => 'false',
'url' => "http://www.example.com/");
$curl = curl_init("https://api.dotmaui.com/client/1.1/htmlmin/");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curl);
curl_close($curl);
echo $output;