Readme

Usage:

import { minifyHTML } from "https://esm.town/v/yieldray/minifyHTML"; const minified = await minifyHTML("<html>...</html>", { ...options });

As an API:

import { runVal } from "https://esm.town/v/std/runVal"; const minified = awaitrunVal("yieldray.minifyHTML", "<html>...</html>", { ...options });
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import init, { minify } from "https://wilsonl.in/minify-html/deno/0.11.1/index.js";
await init();
const encoder = new TextEncoder();
const decoder = new TextDecoder();
export async function minifyHTML(html: string, options?: Partial<MinifyHTMLOptions>) {
return decoder.decode(minify(encoder.encode(html), options));
}
export interface MinifyHTMLOptions {
/**
* Do not minify DOCTYPEs. Minified DOCTYPEs may not be spec compliant.
*/
do_not_minify_doctype: boolean;
/**
* Ensure all unquoted attribute values in the output do not contain any characters prohibited by the WHATWG specification.
*/
ensure_spec_compliant_unquoted_attribute_values: boolean;
/**
* Do not omit closing tags when possible.
*/
keep_closing_tags: boolean;
/**
* Do not omit <html> and <head> opening tags when they don’t have attributes.
*/
keep_html_and_head_opening_tags: boolean;
/**
* Keep spaces between attributes when possible to conform to HTML standards.
*/
keep_spaces_between_attributes: boolean;
/**
* Keep all comments.
*/
keep_comments: boolean;
/**
* Minify CSS in <style> tags and style attributes using https://github.com/Mnwa/css-minify. By default, the optimisation level is 1 as specified by the CSS minifier, but this can be adjusted by the minify_css_level_* settings.
*/
minify_css: boolean;
/**
* Use optimisation level 1 for the CSS minifier. This is currently the default, but may change in the future if higher levels become safe.
*/
minify_css_level_1: boolean;
/**
* Use optimisation level 2 for the CSS minifier. This is mostly safe, but may perform some dangerous optimisations.
*/
minify_css_level_2: boolean;
/**
* Use optimisation level 3 for the CSS minifier. This performs many dangerous optimisations, so ensure any input works with this level.
*/
minify_css_level_3: boolean;
/**
* Minify JavaScript in <script> tags using minify-js.
* Only <script> tags with a valid or no MIME type is considered to contain JavaScript, as per the specification.
*/
minify_js: boolean;
/**
* Remove all bangs.
*/
remove_bangs: boolean;
/**
* Remove all processing_instructions.
*/
remove_processing_instructions: boolean;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v6
December 29, 2023