Hello, world!
".to_vec(); let cfg = &Cfg { minify_js: false, }; // Minifies a slice in-place and returns the new minified length, // but leaves any original code after the minified code intact. match in_place(&mut code, cfg) { Ok(minified_len) => {} Err(Error { error_type, position }) => {} }; // Creates a vector copy containing only minified code // instead of minifying in-place. match copy(&code, cfg) { Ok(minified) => {} Err(Error { error_type, position }) => {} }; // Minifies a vector in-place, and then truncates the // vector to the new minified length. match truncate(&mut code, cfg) { Ok(()) => {} Err(Error { error_type, position }) => {} }; // Identical to `in_place` except with FriendlyError instead. // `code_context` is a string of a visual representation of the source, // with line numbers and position markers to aid in debugging syntax. match with_friendly_error(&mut code, cfg) { Ok(minified_len) => {} Err(FriendlyError { position, message, code_context }) => { eprintln!("Failed at character {}:", position); eprintln!("{}", message); eprintln!("{}", code_context); } }; } ```Hello, world!
", cfg); // Alternatively, minify in place to avoid copying. const source = Buffer.from("Hello, world!
"); // This is a Buffer representing a slice of `source`, not newly allocated memory. const minified = minifyHtml.minifyInPlace(source, cfg); ``` minify-html is also available for TypeScript: ```ts import * as minifyHtml from "@minify-html/js"; import * as fs from "fs"; const cfg = minifyHtml.createConfiguration({ minifyJs: false }); const minified = minifyHtml.minify("Hello, world!
", cfg); // Or alternatively: const minified = minifyHtml.minifyInPlace(fs.readFileSync("source.html"), cfg); ```Hello, world!
", cfg); } catch (MinifyHtml.SyntaxException e) { System.err.println(e.getMessage()); } // Alternatively, minify in place: assert source instanceof ByteBuffer && source.isDirect(); MinifyHtml.minifyInPlace(source, cfg); ```Hello, world!
", minify_js=False) except SyntaxError as e: print(e) ```Hello, world!
", { :minify_js => false }) ```Before | After |
---|---|
```html
↵ ··The·quick·brown·fox↵ ··jumps·over·the·lazy↵ ··dog.↵ ``` |
```html
·The·quick·brown·fox·jumps·over·the·lazy·dog.· ``` |
Before | After |
---|---|
```html
|
```html
|
Before | After |
---|---|
```html
↵ ··Hey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1]↵ ``` |
```html
Hey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1] ``` |
↵ ··Hey,·I·just·found↵ ··out·about·this·cool·website!↵ ··[1]↵
``` ###### After ```htmlHey,·I·just·found·out·about·this·cool·website!·[1]
```