minify_html 0.4.11 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +65 -74
- data/lib/linux-ruby2.5 +0 -0
- data/lib/linux-ruby2.6 +0 -0
- data/lib/linux-ruby2.7 +0 -0
- data/lib/macos-ruby2.5 +0 -0
- data/lib/macos-ruby2.6 +0 -0
- data/lib/macos-ruby2.7 +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ac8cbe2a24743c576effe99e4939533da0826c3e5e460b0b1a59268516aef52
|
4
|
+
data.tar.gz: 12d1e2786e277c1b3eda39ab17daa9aae14623573aa06b0ddc4773ceb405d19f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef289f74abbc2070211d94a0dee6f201cffc0edb340e822c27420f965824456f174114850bca2c80a48f1a903f0571b51045c639c4d678c076840ea28c04329a
|
7
|
+
data.tar.gz: 150e46bc7dff5da38d56c8415f3420f5c7d69f218ba0a19f6639bb0df03d33ea40571ba496a2e81a15cb7a284222fab2896a008a3fc8e1a26653d988f750e1d9
|
data/README.md
CHANGED
@@ -1,69 +1,80 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
<h1>
|
2
|
+
minify-html
|
3
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/cli.png">
|
4
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/java.png">
|
5
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png">
|
6
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/python.png">
|
7
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/ruby.png">
|
8
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/rust.png">
|
9
|
+
</h1>
|
10
|
+
|
11
|
+
A Rust HTML minifier meticulously optimised for speed and effectiveness, with bindings for other languages.
|
12
|
+
|
13
|
+
- Advanced minification strategy beats other minifiers while being much faster.
|
14
|
+
- Uses SIMD searching, direct tries, and lookup tables.
|
15
|
+
- Handles [invalid HTML](./notes/Parsing.md), with extensive testing and [fuzzing](./fuzz).
|
9
16
|
- Natively binds to [esbuild](https://github.com/wilsonzlin/esbuild-rs) for super fast JS and CSS minification.
|
10
17
|
|
11
18
|
## Performance
|
12
19
|
|
13
20
|
Comparison with [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize), run on the top web pages. [See the breakdown here.](./bench)
|
14
21
|
|
15
|
-
<img width="415" alt="Chart showing speed
|
22
|
+
<img width="415" alt="Chart showing speed and compression of HTML minifiers" src="https://wilsonl.in/minify-html/bench/0.6.0/core/average-combined.png">
|
23
|
+
|
24
|
+
Need even faster performance? Check the [one](https://github.com/wilsonzlin/minify-html/tree/one) branch.
|
16
25
|
|
17
26
|
## Usage
|
18
27
|
|
19
|
-
|
28
|
+
<details>
|
29
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/cli.png"> <strong>CLI</strong></summary>
|
20
30
|
|
21
|
-
Precompiled binaries are available for
|
31
|
+
Precompiled binaries are available for Linux, macOS, and Windows.
|
22
32
|
|
23
|
-
|
33
|
+
### Get
|
24
34
|
|
25
|
-
[Linux](https://wilsonl.in/minify-html/bin/0.
|
26
|
-
[
|
27
|
-
[
|
35
|
+
[Linux x86-64](https://wilsonl.in/minify-html/bin/0.6.0-linux-x86_64) |
|
36
|
+
[Linux ARM](https://wilsonl.in/minify-html/bin/0.6.0-linux-arm64) |
|
37
|
+
[macOS](https://wilsonl.in/minify-html/bin/0.6.0-macos-x86_64) |
|
38
|
+
[Windows](https://wilsonl.in/minify-html/bin/0.6.0-windows-x86_64.exe)
|
28
39
|
|
29
|
-
|
40
|
+
### Use
|
30
41
|
|
31
42
|
Use the `--help` argument for more details.
|
32
43
|
|
33
44
|
```bash
|
34
|
-
minify-html --
|
45
|
+
minify-html --output /path/to/output.min.html --keep-closing-tags --minify-css /path/to/src.html
|
35
46
|
```
|
36
47
|
|
37
|
-
|
48
|
+
</details>
|
38
49
|
|
39
50
|
<details>
|
40
|
-
<summary><strong>Rust</strong></summary>
|
51
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/rust.png"> <strong>Rust</strong></summary>
|
41
52
|
|
42
|
-
|
53
|
+
### Get
|
43
54
|
|
44
55
|
```toml
|
45
56
|
[dependencies]
|
46
|
-
minify-html = { version = "0.
|
57
|
+
minify-html = { version = "0.6.0", features = ["js-esbuild"] }
|
47
58
|
```
|
48
59
|
|
49
60
|
Building with the `js-esbuild` feature requires the Go compiler to be installed as well, to build the [JS and CSS minifier](https://github.com/wilsonzlin/esbuild-rs).
|
50
61
|
|
51
62
|
If the `js-esbuild` feature is not enabled, `cfg.minify_js` and `cfg.minify_css` will have no effect.
|
52
63
|
|
53
|
-
|
64
|
+
### Use
|
54
65
|
|
55
66
|
Check out the [docs](https://docs.rs/minify-html) for API and usage examples.
|
56
67
|
|
57
68
|
</details>
|
58
69
|
|
59
70
|
<details>
|
60
|
-
<summary><strong>Node.js</strong></summary>
|
71
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png"> <strong>Node.js</strong></summary>
|
61
72
|
|
62
73
|
- Package: [@minify-html/js](https://www.npmjs.com/package/@minify-html/js)
|
63
74
|
- Binding: [N-API](https://nodejs.org/api/n-api.html)
|
64
|
-
- Platforms: Linux, macOS, Windows; Node.js 8.6.0 and higher
|
75
|
+
- Platforms: Linux (ARM64 and x86-64), macOS (x86-64), Windows (x86-64); Node.js 8.6.0 and higher
|
65
76
|
|
66
|
-
|
77
|
+
### Get
|
67
78
|
|
68
79
|
Using npm:
|
69
80
|
|
@@ -77,18 +88,14 @@ Using Yarn:
|
|
77
88
|
yarn add @minify-html/js
|
78
89
|
```
|
79
90
|
|
80
|
-
|
91
|
+
### Use
|
81
92
|
|
82
93
|
```js
|
83
94
|
const minifyHtml = require("@minify-html/js");
|
84
95
|
|
85
|
-
|
96
|
+
// Refer to TypeScript definitions for details.
|
97
|
+
const cfg = minifyHtml.createConfiguration({ keep_closing_tags: true, remove_bangs: false });
|
86
98
|
const minified = minifyHtml.minify("<p> Hello, world! </p>", cfg);
|
87
|
-
|
88
|
-
// Alternatively, minify in place to avoid copying.
|
89
|
-
const source = Buffer.from("<p> Hello, world! </p>");
|
90
|
-
// This is a Buffer representing a slice of `source`, not newly allocated memory.
|
91
|
-
const minified = minifyHtml.minifyInPlace(source, cfg);
|
92
99
|
```
|
93
100
|
|
94
101
|
minify-html is also available for TypeScript:
|
@@ -97,22 +104,20 @@ minify-html is also available for TypeScript:
|
|
97
104
|
import * as minifyHtml from "@minify-html/js";
|
98
105
|
import * as fs from "fs";
|
99
106
|
|
100
|
-
const cfg = minifyHtml.createConfiguration({
|
107
|
+
const cfg = minifyHtml.createConfiguration({ keep_spaces_between_attributes: true, keep_comments: true });
|
101
108
|
const minified = minifyHtml.minify("<p> Hello, world! </p>", cfg);
|
102
|
-
// Or alternatively:
|
103
|
-
const minified = minifyHtml.minifyInPlace(fs.readFileSync("source.html"), cfg);
|
104
109
|
```
|
105
110
|
|
106
111
|
</details>
|
107
112
|
|
108
113
|
<details>
|
109
|
-
<summary><strong>Java</strong></summary>
|
114
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/java.png"> <strong>Java</strong></summary>
|
110
115
|
|
111
116
|
- Package: [in.wilsonl.minifyhtml](https://search.maven.org/artifact/in.wilsonl.minifyhtml/minify-html)
|
112
117
|
- Binding: [JNI](https://github.com/jni-rs/jni-rs)
|
113
118
|
- Platforms: Linux, macOS, Windows; Java 7 and higher
|
114
119
|
|
115
|
-
|
120
|
+
### Get
|
116
121
|
|
117
122
|
Add as a Maven dependency:
|
118
123
|
|
@@ -120,11 +125,11 @@ Add as a Maven dependency:
|
|
120
125
|
<dependency>
|
121
126
|
<groupId>in.wilsonl.minifyhtml</groupId>
|
122
127
|
<artifactId>minify-html</artifactId>
|
123
|
-
<version>0.
|
128
|
+
<version>0.6.0</version>
|
124
129
|
</dependency>
|
125
130
|
```
|
126
131
|
|
127
|
-
|
132
|
+
### Use
|
128
133
|
|
129
134
|
```java
|
130
135
|
import in.wilsonl.minifyhtml.Configuration;
|
@@ -132,71 +137,60 @@ import in.wilsonl.minifyhtml.MinifyHtml;
|
|
132
137
|
import in.wilsonl.minifyhtml.SyntaxException;
|
133
138
|
|
134
139
|
Configuration cfg = new Configuration.Builder()
|
135
|
-
.
|
136
|
-
.setMinifyCss(
|
140
|
+
.setKeepHtmlAndHeadOpeningTags(true)
|
141
|
+
.setMinifyCss(true)
|
137
142
|
.build();
|
138
143
|
|
139
|
-
|
140
|
-
String minified = MinifyHtml.minify("<p> Hello, world! </p>", cfg);
|
141
|
-
} catch (SyntaxException e) {
|
142
|
-
System.err.println(e.getMessage());
|
143
|
-
}
|
144
|
-
|
145
|
-
// Alternatively, minify in place:
|
146
|
-
assert source instanceof ByteBuffer && source.isDirect();
|
147
|
-
MinifyHtml.minifyInPlace(source, cfg);
|
144
|
+
String minified = MinifyHtml.minify("<p> Hello, world! </p>", cfg);
|
148
145
|
```
|
149
146
|
|
150
147
|
</details>
|
151
148
|
|
152
149
|
<details>
|
153
|
-
<summary><strong>Python</strong></summary>
|
150
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/python.png"> <strong>Python</strong></summary>
|
154
151
|
|
155
152
|
- Package: [minify-html](https://pypi.org/project/minify-html)
|
156
153
|
- Binding: [PyO3](https://github.com/PyO3/pyo3)
|
157
154
|
- Platforms: Linux, macOS, Windows; Python 3.7 and higher
|
158
155
|
|
159
|
-
|
156
|
+
### Get
|
160
157
|
|
161
158
|
Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
|
162
159
|
|
163
|
-
|
160
|
+
### Use
|
164
161
|
|
165
162
|
```python
|
166
163
|
import minify_html
|
167
164
|
|
168
|
-
|
169
|
-
minified = minify_html.minify("<p> Hello, world! </p>", minify_js=False, minify_css=False)
|
170
|
-
except SyntaxError as e:
|
171
|
-
print(e)
|
165
|
+
minified = minify_html.minify("<p> Hello, world! </p>", minify_js=True, remove_processing_instructions=True)
|
172
166
|
```
|
173
167
|
|
174
168
|
</details>
|
175
169
|
|
176
170
|
<details>
|
177
|
-
<summary><strong>Ruby</strong></summary>
|
171
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/ruby.png"> <strong>Ruby</strong></summary>
|
178
172
|
|
179
173
|
- Package: [minify_html](https://rubygems.org/gems/minify_html)
|
180
174
|
- Binding: [Rutie](https://github.com/danielpclark/rutie)
|
181
175
|
- Platforms: Linux, macOS; Ruby 2.5 and higher
|
182
176
|
|
183
|
-
|
177
|
+
### Get
|
184
178
|
|
185
179
|
Add the library as a dependency to `Gemfile` or `*.gemspec`.
|
186
180
|
|
187
|
-
|
181
|
+
### Use
|
188
182
|
|
189
183
|
```ruby
|
190
184
|
require 'minify_html'
|
191
185
|
|
192
|
-
print MinifyHtml.minify("<p> Hello, world! </p>", { :
|
186
|
+
print MinifyHtml.minify("<p> Hello, world! </p>", { :keep_spaces_between_attributes => true, :minify_js => true })
|
193
187
|
```
|
194
188
|
|
195
189
|
</details>
|
196
190
|
|
197
191
|
## Minification
|
198
192
|
|
199
|
-
Note that
|
193
|
+
Note that some of the minification done can result in HTML that will not pass validation, but remain interpreted and rendered correctly by the browser; essentially, the laxness of the browser is taken advantage of for better minification. These can be turned off via the `Cfg` object.
|
200
194
|
|
201
195
|
### Whitespace
|
202
196
|
|
@@ -390,7 +384,7 @@ These elements are usually like content elements but are occasionally used like
|
|
390
384
|
|
391
385
|
### Tags
|
392
386
|
|
393
|
-
[Optional closing tags](https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission) are removed.
|
387
|
+
[Optional opening and closing tags](https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission) are removed.
|
394
388
|
|
395
389
|
### Attributes
|
396
390
|
|
@@ -400,26 +394,25 @@ Any entities in attribute values are decoded, and then the shortest representati
|
|
400
394
|
- Single quoted, with any `'` encoded.
|
401
395
|
- Unquoted, with `"`/`'` first character (if applicable), any `>`, and any whitespace encoded.
|
402
396
|
|
403
|
-
|
397
|
+
Attributes have their whitespace (after any decoding) trimmed and collapsed when possible.
|
404
398
|
|
405
|
-
[Boolean attribute](
|
406
|
-
[Some other attributes](
|
399
|
+
[Boolean attribute](https://github.com/wilsonzlin/html-data) values are removed.
|
400
|
+
[Some other attributes](https://github.com/wilsonzlin/html-data) are completely removed if their value is empty or the default value after any processing.
|
407
401
|
|
408
402
|
`type` attributes on `script` tags with a value equaling a [JavaScript MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) are removed.
|
409
403
|
|
410
404
|
If an attribute value is empty after any processing, everything but the name is completely removed (i.e. no `=`), as an empty attribute is implicitly [the same](https://html.spec.whatwg.org/multipage/syntax.html#attributes-2) as an attribute with an empty string value.
|
411
405
|
|
412
|
-
Spaces are removed between attributes
|
406
|
+
Spaces are removed between attributes when possible.
|
413
407
|
|
414
408
|
### Entities
|
415
409
|
|
416
|
-
Entities are decoded if they're valid and shorter or equal in length when decoded.
|
410
|
+
Entities are decoded if they're valid and shorter or equal in length when decoded. UTF-8 sequences that have a shorter entity representation are encoded.
|
417
411
|
|
418
412
|
Numeric entities that do not refer to a valid [Unicode Scalar Value](https://www.unicode.org/glossary/#unicode_scalar_value) are replaced with the [replacement character](https://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character).
|
419
413
|
|
420
|
-
|
421
|
-
|
422
|
-
Note that it's possible to get an unintentional entity after removing comments, e.g. `&am<!-- -->p`; minify-html will **not** encode the leading ampersand.
|
414
|
+
Encoding is avoided when possible; for example, `<` are only encoded in content if they are followed by a valid tag name character.
|
415
|
+
If necessary, the shortest entity representation is chosen.
|
423
416
|
|
424
417
|
### Comments
|
425
418
|
|
@@ -431,9 +424,7 @@ Bangs, [processing instructions](https://en.wikipedia.org/wiki/Processing_Instru
|
|
431
424
|
|
432
425
|
## Parsing
|
433
426
|
|
434
|
-
-
|
435
|
-
- Opening tags must not be [omitted](https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission).
|
436
|
-
- [Escaped and double-escaped](./notes/Script%20data.md) script content are not supported.
|
427
|
+
minify-html can process any HTML, handling all possible syntax (including invalid ones) gracefully like browsers. See [Parsing.md](./notes/Parsing.md) for more details.
|
437
428
|
|
438
429
|
## Issues and contributions
|
439
430
|
|
data/lib/linux-ruby2.5
CHANGED
Binary file
|
data/lib/linux-ruby2.6
CHANGED
Binary file
|
data/lib/linux-ruby2.7
CHANGED
Binary file
|
data/lib/macos-ruby2.5
CHANGED
Binary file
|
data/lib/macos-ruby2.6
CHANGED
Binary file
|
data/lib/macos-ruby2.7
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minify_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fiddle
|