minify_html 0.12.0-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +492 -0
- data/lib/2.7/minify_html.bundle +0 -0
- data/lib/3.0/minify_html.bundle +0 -0
- data/lib/3.1/minify_html.bundle +0 -0
- data/lib/3.2/minify_html.bundle +0 -0
- data/lib/minify_html.rb +8 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c856ef36653f2e12e6699c7f77728d9769dfd08e57510f5569f61b64bc396451
|
4
|
+
data.tar.gz: f308480d78eb518b578953e4e1cb631f875b00e34209a2070332782c17987bfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d34da0c38014d385a245aa4ea98c96e4a28c1b3f004281041c96902e812c4858efc5898e974e827e1422824ab4d6649c19599de7b00d67835d72319fa8c951f1
|
7
|
+
data.tar.gz: cdd96bd22410909ac8c9415cd96a1ee3c4888aa674280b360e59520b9faf836ecd56196529e8b4dc15713b4d9c6ccc5717c0b8ba31034c95a0006ea4d728e354
|
data/README.md
ADDED
@@ -0,0 +1,492 @@
|
|
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/deno.png">
|
5
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/java.png">
|
6
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png">
|
7
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/python.png">
|
8
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/ruby.png">
|
9
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/rust.png">
|
10
|
+
<img width="24" src="https://wilsonl.in/minify-html/icon/wasm.png">
|
11
|
+
</h1>
|
12
|
+
|
13
|
+
A Rust HTML minifier meticulously optimised for speed and effectiveness, with bindings for other languages.
|
14
|
+
|
15
|
+
- Advanced minification strategy beats other minifiers while being much faster.
|
16
|
+
- Uses SIMD searching, direct tries, and lookup tables.
|
17
|
+
- Handles [invalid HTML](./notes/Parsing.md), with extensive testing and [fuzzing](./fuzz).
|
18
|
+
- Uses [minify-js](https://github.com/wilsonzlin/minify-js) for super fast JS minification.
|
19
|
+
|
20
|
+
View the [changelog](./CHANGELOG.md) to see the latest updates.
|
21
|
+
|
22
|
+
## Performance
|
23
|
+
|
24
|
+
Comparison with [html-minifier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize), run on the top web pages. [See the breakdown here.](./bench)
|
25
|
+
|
26
|
+
<img width="400" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/minify-html/bench/0.12.0/core/average-speeds.png"><img width="400" alt="Chart showing compression of HTML minifiers" src="https://wilsonl.in/minify-html/bench/0.12.0/core/average-sizes.png">
|
27
|
+
|
28
|
+
The [onepass](https://github.com/wilsonzlin/minify-html/tree/master/rust/onepass) variant is even more optimised for speed. See its [README](https://github.com/wilsonzlin/minify-html/tree/master/rust/onepass) for more details.
|
29
|
+
|
30
|
+
## Compatibility and usage
|
31
|
+
|
32
|
+
<details>
|
33
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/cli.png"> <strong>CLI</strong></summary>
|
34
|
+
|
35
|
+
Precompiled binaries are available for Linux, macOS, and Windows.
|
36
|
+
|
37
|
+
### Get
|
38
|
+
|
39
|
+
[Linux x64](https://wilsonl.in/minify-html/bin/0.12.0-linux-x86_64) |
|
40
|
+
[Linux ARM64](https://wilsonl.in/minify-html/bin/0.12.0-linux-arm64) |
|
41
|
+
[macOS x64](https://wilsonl.in/minify-html/bin/0.12.0-macos-x86_64) |
|
42
|
+
[Windows x64](https://wilsonl.in/minify-html/bin/0.12.0-windows-x86_64.exe)
|
43
|
+
|
44
|
+
### Use
|
45
|
+
|
46
|
+
Use the `--help` argument for more details.
|
47
|
+
|
48
|
+
```bash
|
49
|
+
minify-html --output /path/to/output.min.html --keep-closing-tags --minify-css /path/to/src.html
|
50
|
+
```
|
51
|
+
|
52
|
+
To quickly parallel process a batch of files in place:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
minify-html --keep-closing-tags --minify-css /path/to/**/*.html
|
56
|
+
```
|
57
|
+
|
58
|
+
</details>
|
59
|
+
|
60
|
+
<details>
|
61
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/rust.png"> <strong>Rust</strong></summary>
|
62
|
+
|
63
|
+
### Get
|
64
|
+
|
65
|
+
```toml
|
66
|
+
[dependencies]
|
67
|
+
minify-html = "0.12.0"
|
68
|
+
```
|
69
|
+
|
70
|
+
### Use
|
71
|
+
|
72
|
+
Check out the [docs](https://docs.rs/minify-html) for API and usage examples.
|
73
|
+
|
74
|
+
</details>
|
75
|
+
|
76
|
+
<details>
|
77
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/deno.png"> <strong>Deno</strong></summary>
|
78
|
+
|
79
|
+
- Package: https://wilsonl.in/minify-html/deno/0.12.0/index.js
|
80
|
+
- Binding: [WASM](https://webassembly.org/)
|
81
|
+
- Platforms: All
|
82
|
+
|
83
|
+
### Use
|
84
|
+
|
85
|
+
```ts
|
86
|
+
import init, {minify} from "https://wilsonl.in/minify-html/deno/0.12.0/index.js";
|
87
|
+
|
88
|
+
const encoder = new TextEncoder();
|
89
|
+
const decoder = new TextDecoder();
|
90
|
+
|
91
|
+
await init();
|
92
|
+
|
93
|
+
const minified = decoder.decode(minify(encoder.encode("<p> Hello, world! </p>"), { keep_spaces_between_attributes: true, keep_comments: true }));
|
94
|
+
```
|
95
|
+
|
96
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available as snake_case properties on the object provided as the second argument; if any are not set, they default to `false`.
|
97
|
+
|
98
|
+
</details>
|
99
|
+
|
100
|
+
<details>
|
101
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/nodejs.png"> <strong>Node.js</strong></summary>
|
102
|
+
|
103
|
+
- Package: [@minify-html/node](https://www.npmjs.com/package/@minify-html/node)
|
104
|
+
- Binding: [Neon](https://github.com/neon-bindings/neon)
|
105
|
+
- Platforms: Linux (ARM64 and x64), macOS (ARM64 and x64), Windows (x64); Node.js 8.6.0 and higher
|
106
|
+
|
107
|
+
### Get
|
108
|
+
|
109
|
+
Using npm:
|
110
|
+
|
111
|
+
```bash
|
112
|
+
npm i @minify-html/node
|
113
|
+
```
|
114
|
+
|
115
|
+
Using Yarn:
|
116
|
+
|
117
|
+
```bash
|
118
|
+
yarn add @minify-html/node
|
119
|
+
```
|
120
|
+
|
121
|
+
### Use
|
122
|
+
|
123
|
+
TypeScript definitions are available.
|
124
|
+
|
125
|
+
```ts
|
126
|
+
import { Buffer } from "node:buffer";
|
127
|
+
import minifyHtml from "@minify-html/node";
|
128
|
+
// Or `const minifyHtml = require("@minify-html/node")` if not using TS/ESM.
|
129
|
+
|
130
|
+
const minified = minifyHtml.minify(Buffer.from("<p> Hello, world! </p>"), { keep_spaces_between_attributes: true, keep_comments: true });
|
131
|
+
```
|
132
|
+
|
133
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available as snake_case properties on the object provided as the second argument; if any are not set, they default to `false`.
|
134
|
+
|
135
|
+
</details>
|
136
|
+
|
137
|
+
<details>
|
138
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/java.png"> <strong>Java</strong></summary>
|
139
|
+
|
140
|
+
- Package: [in.wilsonl.minifyhtml](https://search.maven.org/artifact/in.wilsonl.minifyhtml/minify-html)
|
141
|
+
- Binding: [JNI](https://github.com/jni-rs/jni-rs)
|
142
|
+
- Platforms: Linux, macOS, Windows; Java 7 and higher
|
143
|
+
|
144
|
+
### Get
|
145
|
+
|
146
|
+
Add as a Maven dependency:
|
147
|
+
|
148
|
+
```xml
|
149
|
+
<dependency>
|
150
|
+
<groupId>in.wilsonl.minifyhtml</groupId>
|
151
|
+
<artifactId>minify-html</artifactId>
|
152
|
+
<version>0.12.0</version>
|
153
|
+
</dependency>
|
154
|
+
```
|
155
|
+
|
156
|
+
### Use
|
157
|
+
|
158
|
+
```java
|
159
|
+
import in.wilsonl.minifyhtml.Configuration;
|
160
|
+
import in.wilsonl.minifyhtml.MinifyHtml;
|
161
|
+
|
162
|
+
Configuration cfg = new Configuration.Builder()
|
163
|
+
.setKeepHtmlAndHeadOpeningTags(true)
|
164
|
+
.setMinifyCss(true)
|
165
|
+
.build();
|
166
|
+
|
167
|
+
String minified = MinifyHtml.minify("<p> Hello, world! </p>", cfg);
|
168
|
+
```
|
169
|
+
|
170
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available as camelCase setter methods on the `Builder`; if any are not set, they default to `false`.
|
171
|
+
|
172
|
+
</details>
|
173
|
+
|
174
|
+
<details>
|
175
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/python.png"> <strong>Python</strong></summary>
|
176
|
+
|
177
|
+
- Package: [minify-html](https://pypi.org/project/minify-html)
|
178
|
+
- Binding: [PyO3](https://github.com/PyO3/pyo3)
|
179
|
+
- Platforms: Linux (ARM64 and x64), macOS (ARM64 and x64), Windows (x64); Python 3.8 to 3.12
|
180
|
+
|
181
|
+
### Get
|
182
|
+
|
183
|
+
Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
|
184
|
+
|
185
|
+
### Use
|
186
|
+
|
187
|
+
```python
|
188
|
+
import minify_html
|
189
|
+
|
190
|
+
minified = minify_html.minify("<p> Hello, world! </p>", minify_js=True, remove_processing_instructions=True)
|
191
|
+
```
|
192
|
+
|
193
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available as Python keyword arguments; if any are omitted, they default to `False`.
|
194
|
+
|
195
|
+
</details>
|
196
|
+
|
197
|
+
<details>
|
198
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/ruby.png"> <strong>Ruby</strong></summary>
|
199
|
+
|
200
|
+
- Package: [minify_html](https://rubygems.org/gems/minify_html)
|
201
|
+
- Binding: [rb-sys](https://github.com/oxidize-rb/rb-sys) and [magnus](https://github.com/matsadler/magnus)
|
202
|
+
- Platforms: Linux (ARM64 and x64), macOS (ARM64 and x64), Windows (x64); Ruby 2.7 to 3.2
|
203
|
+
|
204
|
+
### Get
|
205
|
+
|
206
|
+
Add the library as a dependency to `Gemfile` or `*.gemspec`.
|
207
|
+
|
208
|
+
### Use
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
require 'minify_html'
|
212
|
+
|
213
|
+
print minify_html("<p> Hello, world! </p>", { :keep_spaces_between_attributes => true, :minify_js => true })
|
214
|
+
```
|
215
|
+
|
216
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available; if any are omitted, they default to `false`.
|
217
|
+
|
218
|
+
</details>
|
219
|
+
|
220
|
+
<details>
|
221
|
+
<summary><img width="24" src="https://wilsonl.in/minify-html/icon/wasm.png"> <strong>WASM</strong></summary>
|
222
|
+
|
223
|
+
- Package: [@minify-html/wasm](https://npmjs.org/package/@minify-html/wasm)
|
224
|
+
- Binding: [WASM](https://webassembly.org/)
|
225
|
+
- Platforms: All
|
226
|
+
|
227
|
+
A bundler may be required to use the WebAssembly module, see [this](https://rustwasm.github.io/wasm-bindgen/reference/deployment.html#bundlers) for more details.
|
228
|
+
|
229
|
+
### Use
|
230
|
+
|
231
|
+
```ts
|
232
|
+
import init, {minify} from "@minify-html/wasm";
|
233
|
+
|
234
|
+
const encoder = new TextEncoder();
|
235
|
+
const decoder = new TextDecoder();
|
236
|
+
|
237
|
+
await init();
|
238
|
+
|
239
|
+
const minified = decoder.decode(minify(encoder.encode("<p> Hello, world! </p>"), { keep_spaces_between_attributes: true, keep_comments: true }));
|
240
|
+
```
|
241
|
+
|
242
|
+
All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.html) are available as snake_case properties on the object provided as the second argument; if any are not set, they default to `false`.
|
243
|
+
|
244
|
+
</details>
|
245
|
+
|
246
|
+
## Minification
|
247
|
+
|
248
|
+
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. To prevent this, refer to these configuration options:
|
249
|
+
|
250
|
+
- `do_not_minify_doctype`
|
251
|
+
- `ensure_spec_compliant_unquoted_attribute_values`
|
252
|
+
- `keep_spaces_between_attributes`
|
253
|
+
|
254
|
+
### Whitespace
|
255
|
+
|
256
|
+
minify-html has advanced context-aware whitespace minification that does things such as:
|
257
|
+
|
258
|
+
- Leave whitespace untouched in `pre` and `code`, which are whitespace sensitive.
|
259
|
+
- Trim and collapse whitespace in content tags, as whitespace is collapsed anyway when rendered.
|
260
|
+
- Remove whitespace in layout tags, which allows the use of inline layouts while keeping formatted code.
|
261
|
+
|
262
|
+
#### Methods
|
263
|
+
|
264
|
+
There are three whitespace minification methods. When processing text content, minify-html chooses which ones to use depending on the containing element.
|
265
|
+
|
266
|
+
<details>
|
267
|
+
<summary><strong>Collapse whitespace</strong></summary>
|
268
|
+
|
269
|
+
> **Applies to:** any element except [whitespace sensitive](./minify-html-common/src/spec/tag/whitespace.rs) elements.
|
270
|
+
|
271
|
+
Reduce a sequence of whitespace characters in text nodes to a single space (U+0020).
|
272
|
+
|
273
|
+
<table><thead><tr><th>Before<th>After<tbody><tr><td>
|
274
|
+
|
275
|
+
```html
|
276
|
+
<p>↵
|
277
|
+
··The·quick·brown·fox↵
|
278
|
+
··jumps·over·the·lazy↵
|
279
|
+
··dog.↵
|
280
|
+
</p>
|
281
|
+
```
|
282
|
+
|
283
|
+
<td>
|
284
|
+
|
285
|
+
```html
|
286
|
+
<p>·The·quick·brown·fox·jumps·over·the·lazy·dog.·</p>
|
287
|
+
```
|
288
|
+
|
289
|
+
</table>
|
290
|
+
</details>
|
291
|
+
|
292
|
+
<details>
|
293
|
+
<summary><strong>Destroy whole whitespace</strong></summary>
|
294
|
+
|
295
|
+
> **Applies to:** any element except [whitespace sensitive](./minify-html-common/src/spec/tag/whitespace.rs), [content](src/spec/tag/whitespace.rs), [content-first](./minify-html-common/src/spec/tag/whitespace.rs), and [formatting](./minify-html-common/src/spec/tag/whitespace.rs) elements.
|
296
|
+
|
297
|
+
Remove any text nodes between tags that only consist of whitespace characters.
|
298
|
+
|
299
|
+
<table><thead><tr><th>Before<th>After<tbody><tr><td>
|
300
|
+
|
301
|
+
```html
|
302
|
+
<ul>↵
|
303
|
+
··<li>A</li>↵
|
304
|
+
··<li>B</li>↵
|
305
|
+
··<li>C</li>↵
|
306
|
+
</ul>
|
307
|
+
```
|
308
|
+
|
309
|
+
<td>
|
310
|
+
|
311
|
+
```html
|
312
|
+
<ul>↵
|
313
|
+
··<li>A</li><li>B</li><li>C</li>↵
|
314
|
+
</ul>
|
315
|
+
```
|
316
|
+
|
317
|
+
</table>
|
318
|
+
</details>
|
319
|
+
|
320
|
+
<details>
|
321
|
+
<summary><strong>Trim whitespace</strong></summary>
|
322
|
+
|
323
|
+
> **Applies to:** any element except [whitespace sensitive](./minify-html-common/src/spec/tag/whitespace.rs) and [formatting](./minify-html-common/src/spec/tag/whitespace.rs) elements.
|
324
|
+
|
325
|
+
Remove any leading/trailing whitespace from any leading/trailing text nodes of a tag.
|
326
|
+
|
327
|
+
<table><thead><tr><th>Before<th>After<tbody><tr><td>
|
328
|
+
|
329
|
+
```html
|
330
|
+
<p>↵
|
331
|
+
··Hey,·I·<em>just</em>·found↵
|
332
|
+
··out·about·this·<strong>cool</strong>·website!↵
|
333
|
+
··<sup>[1]</sup>↵
|
334
|
+
</p>
|
335
|
+
```
|
336
|
+
|
337
|
+
<td>
|
338
|
+
|
339
|
+
```html
|
340
|
+
<p>Hey,·I·<em>just</em>·found↵
|
341
|
+
··out·about·this·<strong>cool</strong>·website!↵
|
342
|
+
··<sup>[1]</sup></p>
|
343
|
+
```
|
344
|
+
|
345
|
+
</table>
|
346
|
+
</details>
|
347
|
+
|
348
|
+
#### Element types
|
349
|
+
|
350
|
+
minify-html assumes HTML and SVG elements are used in specific ways, based on standards and best practices. By making these assumptions, it can apply optimal whitespace minification strategies. If these assumptions do not hold, consider adjusting the HTML source or turning off whitespace minification.
|
351
|
+
|
352
|
+
|Group|Elements|Expected children|
|
353
|
+
|---|---|---|
|
354
|
+
|Formatting|`a`, `strong`, [and others](./minify-html-common/src/spec/tag/whitespace.rs)|Formatting elements, text.|
|
355
|
+
|Content|`h1`, `p`, [and others](./minify-html-common/src/spec/tag/whitespace.rs)|Formatting elements, text.|
|
356
|
+
|Layout|`div`, `ul`, [and others](./minify-html-common/src/spec/tag/whitespace.rs)|Layout elements, content elements.|
|
357
|
+
|Content-first|`label`, `li`, [and others](./minify-html-common/src/spec/tag/whitespace.rs)|Like content but could be layout with only one child.|
|
358
|
+
|
359
|
+
<details>
|
360
|
+
<summary><strong>Formatting elements</strong></summary>
|
361
|
+
|
362
|
+
> Whitespace is collapsed.
|
363
|
+
|
364
|
+
Formatting elements are usually inline elements that wrap around part of some text in a content element, so its whitespace isn't trimmed as they're probably part of the content.
|
365
|
+
|
366
|
+
</details>
|
367
|
+
|
368
|
+
<details>
|
369
|
+
<summary><strong>Content elements</strong></summary>
|
370
|
+
|
371
|
+
> Whitespace is trimmed and collapsed.
|
372
|
+
|
373
|
+
Content elements usually represent a contiguous and complete unit of content such as a paragraph. As such, whitespace is significant but sequences of them are most likely due to formatting.
|
374
|
+
|
375
|
+
###### Before
|
376
|
+
|
377
|
+
```html
|
378
|
+
<p>↵
|
379
|
+
··Hey,·I·<em>just</em>·found↵
|
380
|
+
··out·about·this·<strong>cool</strong>·website!↵
|
381
|
+
··<sup>[1]</sup>↵
|
382
|
+
</p>
|
383
|
+
```
|
384
|
+
|
385
|
+
###### After
|
386
|
+
|
387
|
+
```html
|
388
|
+
<p>Hey,·I·<em>just</em>·found·out·about·this·<strong>cool</strong>·website!·<sup>[1]</sup></p>
|
389
|
+
```
|
390
|
+
|
391
|
+
</details>
|
392
|
+
|
393
|
+
<details>
|
394
|
+
<summary><strong>Layout elements</strong></summary>
|
395
|
+
|
396
|
+
> Whitespace is trimmed and collapsed. Whole whitespace is removed.
|
397
|
+
|
398
|
+
These elements should only contain other elements and no text. This makes it possible to remove whole whitespace, which is useful when using `display: inline-block` so that whitespace between elements (e.g. indentation) does not alter layout and styling.
|
399
|
+
|
400
|
+
###### Before
|
401
|
+
|
402
|
+
```html
|
403
|
+
<ul>↵
|
404
|
+
··<li>A</li>↵
|
405
|
+
··<li>B</li>↵
|
406
|
+
··<li>C</li>↵
|
407
|
+
</ul>
|
408
|
+
```
|
409
|
+
|
410
|
+
###### After
|
411
|
+
|
412
|
+
```html
|
413
|
+
<ul><li>A</li><li>B</li><li>C</li></ul>
|
414
|
+
```
|
415
|
+
|
416
|
+
</details>
|
417
|
+
|
418
|
+
<details>
|
419
|
+
<summary><strong>Content-first elements</strong></summary>
|
420
|
+
|
421
|
+
> Whitespace is trimmed and collapsed.
|
422
|
+
|
423
|
+
These elements are usually like content elements but are occasionally used like a layout element with one child. Whole whitespace is not removed as it might contain content, but this is OK for using as layout as there is only one child and whitespace is trimmed.
|
424
|
+
|
425
|
+
###### Before
|
426
|
+
|
427
|
+
```html
|
428
|
+
<li>↵
|
429
|
+
··<article>↵
|
430
|
+
····<section></section>↵
|
431
|
+
····<section></section>↵
|
432
|
+
··</article>↵
|
433
|
+
</li>
|
434
|
+
```
|
435
|
+
|
436
|
+
###### After
|
437
|
+
|
438
|
+
```html
|
439
|
+
<li><article><section></section><section></section></article></li>
|
440
|
+
```
|
441
|
+
|
442
|
+
</details>
|
443
|
+
|
444
|
+
### Tags
|
445
|
+
|
446
|
+
[Optional opening and closing tags](https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission) are removed.
|
447
|
+
|
448
|
+
### Attributes
|
449
|
+
|
450
|
+
Any entities in attribute values are decoded, and then the shortest representation of the value is calculated and used:
|
451
|
+
|
452
|
+
- Double quoted, with any `"` encoded.
|
453
|
+
- Single quoted, with any `'` encoded.
|
454
|
+
- Unquoted, with `"`/`'` first character (if applicable), any `>`, and any whitespace encoded.
|
455
|
+
|
456
|
+
Attributes have their whitespace (after any decoding) trimmed and collapsed when possible.
|
457
|
+
|
458
|
+
[Boolean attribute](https://github.com/wilsonzlin/html-data) values are removed.
|
459
|
+
[Some other attributes](https://github.com/wilsonzlin/html-data) are completely removed if their value is empty or the default value after any processing.
|
460
|
+
|
461
|
+
`type` attributes on `script` tags with a value equaling a [JavaScript MIME type](https://mimesniff.spec.whatwg.org/#javascript-mime-type) are removed.
|
462
|
+
|
463
|
+
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.
|
464
|
+
|
465
|
+
Spaces are removed between attributes when possible.
|
466
|
+
|
467
|
+
### Entities
|
468
|
+
|
469
|
+
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.
|
470
|
+
|
471
|
+
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).
|
472
|
+
|
473
|
+
Encoding is avoided when possible; for example, `<` are only encoded in content if they are followed by a valid tag name character.
|
474
|
+
If necessary, the shortest entity representation is chosen.
|
475
|
+
|
476
|
+
### Comments
|
477
|
+
|
478
|
+
Comments are removed.
|
479
|
+
|
480
|
+
### Ignored
|
481
|
+
|
482
|
+
Bangs, [processing instructions](https://en.wikipedia.org/wiki/Processing_Instruction), and empty elements are not removed as it is assumed there is a special reason for their declaration.
|
483
|
+
|
484
|
+
## Parsing
|
485
|
+
|
486
|
+
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.
|
487
|
+
|
488
|
+
## Issues and contributions
|
489
|
+
|
490
|
+
Pull requests and any contributions welcome!
|
491
|
+
|
492
|
+
If minify-html did something unexpected, misunderstood some syntax, or incorrectly kept/removed some code, [raise an issue](https://github.com/wilsonzlin/minify-html/issues) with some relevant code that can be used to reproduce and investigate the issue.
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/minify_html.rb
ADDED
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: minify_html
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.12.0
|
5
|
+
platform: arm64-darwin
|
6
|
+
authors:
|
7
|
+
- Wilson Lin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake-compiler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- code@wilsonl.in
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/2.7/minify_html.bundle
|
50
|
+
- lib/3.0/minify_html.bundle
|
51
|
+
- lib/3.1/minify_html.bundle
|
52
|
+
- lib/3.2/minify_html.bundle
|
53
|
+
- lib/minify_html.rb
|
54
|
+
homepage: https://github.com/wilsonzlin/minify-html
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '2.7'
|
67
|
+
- - "<"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.3.dev
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubygems_version: 3.4.4
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Extremely fast and smart HTML + JS + CSS minifier
|
80
|
+
test_files: []
|