Description Usage Arguments See Also Examples
This function takes a text string as input and minifies it according to large number of options. The blog post provides a fuller descriptions of the options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | minifyHTML(input, caseSensitive = FALSE,
collapseBooleanAttributes = TRUE,
collapseInlineTagWhitespace = FALSE, collapseWhitespace = TRUE,
conservativeCollapse = FALSE, continueOnParseError = FALSE,
customAttrAssign = "[]", customAttrCollapse = NULL,
customAttrSurround = "[]",
customEventAttributes = "[ /^on[a-z]{3,}$/ ]", decodeEntities = TRUE,
html5 = TRUE, ignoreCustomComments = "[ /^!/ ]",
ignoreCustomFragments = "[ /<%[\\s\\S]*?%>/, /<\\?[,\\s\\S]*?\\?>/ ]",
includeAutoGeneratedTags = TRUE, keepClosingSlash = FALSE,
maxLineLength = NULL, minifyCSS = TRUE, minifyJS = TRUE,
minifyURLs = FALSE, preserveLineBreaks = FALSE,
preventAttributesEscaping = FALSE, processConditionalComments = TRUE,
processScripts = "[]", quoteCharacter = NULL,
removeAttributeQuotes = FALSE, removeComments = TRUE,
removeEmptyAttributes = TRUE, removeEmptyElements = FALSE,
removeOptionalTags = FALSE, removeRedundantAttributes = FALSE,
removeScriptTypeAttributes = FALSE,
removeStyleLinkTypeAttributes = FALSE, removeTagWhitespace = FALSE,
sortAttributes = TRUE, sortClassName = TRUE,
trimCustomFragments = TRUE, useShortDoctype = TRUE)
|
input |
String |
caseSensitive |
Treat attributes in case sensitive manner (useful for custom HTML tags) |
collapseBooleanAttributes |
|
collapseInlineTagWhitespace |
Don't leave any spaces between |
collapseWhitespace |
Collapse white space that contributes to text nodes in a document tree |
conservativeCollapse |
Always collapse to 1 space (never remove it entirely). Must be used in conjunction with |
continueOnParseError |
Handle parse errors instead of aborting. |
customAttrAssign |
Arrays of regex'es that allow to support custom attribute assign expressions (e.g. |
customAttrCollapse |
Regex that specifies custom attribute to strip newlines from (e.g. |
customAttrSurround |
Arrays of regex'es that allow to support custom attribute surround expressions (e.g. |
customEventAttributes |
Arrays of regex'es that allow to support custom event attributes for |
decodeEntities |
Use direct Unicode characters whenever possible |
html5 |
Parse input according to HTML5 specifications |
ignoreCustomComments |
Array of regex'es that allow to ignore certain comments, when matched |
ignoreCustomFragments |
Array of regex'es that allow to ignore certain fragments, when matched (e.g. |
includeAutoGeneratedTags |
Insert tags generated by HTML parser |
keepClosingSlash |
Keep the trailing slash on singleton elements |
maxLineLength |
Specify a maximum line length. Compressed output will be split by newlines at valid HTML split-points |
minifyCSS |
Minify CSS in style elements and style attributes (uses clean-css) |
minifyJS |
Minify JavaScript in script elements and event attributes (uses UglifyJS) |
minifyURLs |
Minify URLs in various attributes (uses relateurl) |
preserveLineBreaks |
Always collapse to 1 line break (never remove it entirely) when whitespace between tags include a line break. Must be used in conjunction with |
preventAttributesEscaping |
Prevents the escaping of the values of attributes |
processConditionalComments |
Process contents of conditional comments through minifier |
processScripts |
Array of strings corresponding to types of script elements to process through minifier (e.g. |
quoteCharacter |
Type of quote to use for attribute values (' or ") |
removeAttributeQuotes |
|
removeComments |
|
removeEmptyAttributes |
|
removeEmptyElements |
|
removeOptionalTags |
|
removeRedundantAttributes |
|
removeScriptTypeAttributes |
Remove |
removeStyleLinkTypeAttributes |
Remove |
removeTagWhitespace |
Remove space between attributes whenever possible. Note that this will result in invalid HTML! |
sortAttributes |
|
sortClassName |
|
trimCustomFragments |
Trim white space around |
useShortDoctype |
html-minifer github page
1 2 | input = "<!-- foo --><div>baz</div><!-- bar\n\n moo -->"
minifyHTML(input)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.