6

Is there a way to minify HTML in Drupal 8, something like the Minify module which is for Drupal 7?

1
  • What is the reason you want to minify the HTML?
    – Eyal
    Commented Jan 27, 2017 at 17:06

2 Answers 2

4

Use spaceless tag. This will not minify the HTML, instead avoids extra whitespace between HTML tags to avoid browser rendering quirks. When cached, can serve better.

In html.html.twig

{% spaceless %}

<!DOCTYPE html>
<html{{ html_attributes }}>
 #rest of the code
</html>

{% endspaceless %}

For compression there is a twig extension

Edit: Use Minify Source HTML module which comes for both D7 and D8.

2
  • After applying this tag Google Page SpeedInsights does not list html minification as a possible improvement anymore. Commented Apr 27, 2017 at 13:53
  • 1
    This tag will only remove extra whitespaces, this will not minify HTML but in some way helps in reducing page size and serves better when cached.
    – echo
    Commented Apr 27, 2017 at 16:51
0

The Advanced CSS/JS Aggregation module has a minify feature:

CSS/JS Compress Submodules. Can minifiy files & inline CSS/JS. Can also turn off core CSS compression for theme development.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.