Skip to main content
Version: 1.4.0

Minify

Mutate Content Optimization

Synopsis

A content optimization processor that minifies XML, JSON, and HTML documents by removing unnecessary whitespace, comments, and other non-essential elements to reduce file size and improve performance.

Schema

- minify:
field: <ident>
format: <enum>
target_field: <ident>
keep_whitespace: <boolean>
keep_comments: <boolean>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
keep_end_tags: <boolean>
keep_document_tags: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Field containing the content to minify
formatY-Content format: xml, json, or html
target_fieldNfieldField to store the minified content
keep_whitespaceNfalsePreserve whitespace in content
keep_commentsNfalsePreserve comments in content
keep_end_tagsNfalsePreserve end tags in HTML (HTML only)
keep_document_tagsNfalsePreserve document tags in HTML (HTML only)
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue if minification fails
ignore_missingNfalseContinue if source field doesn't exist
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier

Details

The processor provides content minification for three primary formats: XML, JSON, and HTML. Each format has specific optimization strategies tailored to its structure and common use cases.

note

Minification is irreversible - ensure you preserve original content if needed.

XML minification removes unnecessary whitespace between elements while preserving content integrity. JSON minification eliminates all non-essential whitespace and formatting. HTML minification offers comprehensive optimization including whitespace removal, comment deletion, and optional tag optimization.

Format-specific options provide fine-grained control over minification behavior. HTML-specific options like keep_end_tags and keep_document_tags allow preservation of structural elements when required.

warning

Test minified content thoroughly as some applications may depend on specific formatting.

Examples

XML Minification

Minifying XML content...

{
"xml_data": "<?xml version=\"1.0\"?>\n<root>\n <item>value</item>\n <!-- comment -->\n</root>"
}
- minify:
field: xml_data
format: xml
target_field: minified_xml

produces compact XML:

{
"xml_data": "<?xml version=\"1.0\"?>\n<root>\n <item>value</item>\n <!-- comment -->\n</root>",
"minified_xml": "<?xml version=\"1.0\"?><root><item>value</item></root>"
}

JSON Minification

Compacting JSON data...

{
"json_content": "{\n \"name\": \"example\",\n \"value\": 123,\n \"nested\": {\n \"key\": \"data\"\n }\n}"
}
- minify:
field: json_content
format: json

removes all formatting:

{
"json_content": "{\"name\":\"example\",\"value\":123,\"nested\":{\"key\":\"data\"}}"
}

HTML Minification

Optimizing HTML content...

{
"html_page": "<!DOCTYPE html>\n<html>\n <head>\n <title>Example</title>\n </head>\n <body>\n <!-- Main content -->\n <div class=\"container\">\n <p>Hello World</p>\n </div>\n </body>\n</html>"
}
- minify:
field: html_page
format: html
target_field: optimized_html

creates compact HTML:

{
"html_page": "<!DOCTYPE html>\n<html>\n <head>\n <title>Example</title>\n </head>\n <body>\n <!-- Main content -->\n <div class=\"container\">\n <p>Hello World</p>\n </div>\n </body>\n</html>",
"optimized_html": "<!doctype html><html><head><title>Example</title><body><div class=container><p>Hello World"
}

Preserving Comments

Minifying while keeping comments...

{
"xml_with_comments": "<config>\n <!-- Important setting -->\n <setting>value</setting>\n</config>"
}
- minify:
field: xml_with_comments
format: xml
keep_comments: true
keep_whitespace: false

preserves important comments:

{
"xml_with_comments": "<config><!-- Important setting --><setting>value</setting></config>"
}

Conditional Minification

Minifying based on content size...

{
"large_json": "{\n \"data\": \"large content here\"\n}",
"content_size": 1024
}
- minify:
field: large_json
format: json
if: "content_size > 500"
target_field: compressed_json

applies minification when needed:

{
"large_json": "{\n \"data\": \"large content here\"\n}",
"content_size": 1024,
"compressed_json": "{\"data\":\"large content here\"}"
}

HTML with Preserved Structure

Minifying HTML while keeping structure...

{
"template": "<html>\n<head></head>\n<body>\n <main>Content</main>\n</body>\n</html>"
}
- minify:
field: template
format: html
keep_end_tags: true
keep_document_tags: true
target_field: clean_template

maintains essential HTML structure:

{
"template": "<html>\n<head></head>\n<body>\n <main>Content</main>\n</body>\n</html>",
"clean_template": "<html><head></head><body><main>Content</main></body></html>"
}