yieldray-minhtml.web.val.run
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import init, { minify } from "https://wilsonl.in/minify-html/deno/0.11.1/index.js";
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;
}
await init();
export default async function(request: Request) {
const url = new URL(request.url);
if (request.method === "GET" || request.method === "HEAD") {
return new Response(String.raw`Usage:
curl "${url.origin}/" \
-d "<html> Hello, world! <!--to be minified--> </html>"
curl "${url.origin}/?do_not_minify_doctype=true&keep_comments=true" \
-d "<!DOCTYPE html><html> Hello, world! <!--keep--> </html>"
Detailed options can be found at:
https://esm.town/v/${
request.url
.match(/^http(?:s):\/\/(\w+)-(\w+)\.web\.val\.run/)!
.slice(1)
.join("/")
}
`);
}
const options: Partial<MinifyHTMLOptions> = Object.fromEntries(
Array.from(url.searchParams.entries()).map(([key, val]) => [
key,
val === "true" ? true : val === "false" ? false : undefined,
]),
);
const result = minify(new Uint8Array(await request.arrayBuffer()), options);
return new Response(result);
}
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!
v1
December 29, 2023