Make your HTML source code pretty and/or compact.
The Beautify module buffers the HTML output of Drupal and processes it through a formatter - aka beautifier plugin.
Available beautifiers:
- Default (HTML): custom set of built-in search/replace functions
- htmLawed: custom battle-tested script (still WIP in #3301617: Implement htmLawed beautifier)
- Tidy: requires Tidy PHP extension installed on your environment
Beautifiers are plugins thus are configurable and extensible. You can create your own beautifier in your custom module too if you want. The default plugin provides functions for beautifying (auto-indentation), flattening (removing indentations) and compacting the HTML source output to the browser.
Page caching is an work in progress in #484756: Cache strategy . This module aims to leverage Drupal's cache so there should be no significant performance penalty, unless of course the chosen processing method increases the HTML file size (e.g. when using beautification over flattening or compacting). In general the flattening mode would provide a nice middle ground between performance improvement and code beautification. Not all options are available from all methods.
How to install
- Download the module
composer require drupal/beautify
- Enable the module
drush en beautify
- Go to admin page Admin > Config > Development > Beautifiers
- Select the default beautifier and edit the configuration
- (optional) Run
drush config-export
to deploy your changes
Known issues
- Beautification can cause problems with textarea input fields as it may strip newlines from the input.
- Tidy HTML can breaks BigPipe rendering and/or Ajax functionalities (e.g. Views pager)
Similar modules
- Tidy HTML: implementation the Tidy HTML library with fewer options.
- Minify HTML
Slack channel
Join the discussion on Slack in the #beautify channel. Details on how to connect to Drupal Slack here.
In memoriam of Richard Burford, original developer of this module whom company - Freestyle Systems - sponsored the development of the D5 and D6 versions.
Project information
- Module categories: Developer Tools, Performance, Integrations
- 3 sites report using this module
- Created by psynaptic on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.