Need Help?

  •   Chat on Gitter
  •   Github Issues
  •   Ask on StackOverflow - tag aahframework

Tutorial of Pluggable HTML Minify

MinifierFunc interface and pluggable option of aah.SetMinifier(...) is introduced in v0.6 release.

Ready to use pluggable implementation is here

How to get the aah tutorials source code?

HTML Minify tutorial application is very simple one. It’s a quick start app using aah new command and applied the below steps.

go get -u -d

Just focus on this file:


Let’s see it in the action

# First let's run the sample application in `dev` environment profile
# Take a moment to look at the page source
aah run -i

# Now, let's run the sample application in `prod` environment profile
# Take a moment look at the page source
aah run -i -e prod

Steps to integrate HTML Minify

Follow the below steps for your aah web application.

Step 1

# HTML minify is using this library, it is recommended to vendor it.
go get -u

# Get the HTML minifier
go get -u

Step 2

Import into your aah project. Implementation comes recommended default values, however you can configure it by following Step 3.

// Import the aah framework HTML minifier
// Note: Minifier gets applied only to `prod` environment profile.
import _ ""

Step 3 (Optional)

Add the configuration into render {...} section of aah.conf then customize it :)

minify {
  keep {
    # To preserve all IE conditional comments such as
    # <!--[if IE 6]><![endif]--> and <![if IE 6]><![endif]>,
    # see
    # Default value is `true`
    conditional_comments = true

    # To preserve html, head and body tags
    # Default value is `true`
    document_tags = true

    # To preserve whitespace between inline tags but still collapse multiple
    # whitespace characters into one
    # Default value is `true`
    whitespace = true

    # To preserve default attribute values such as <script type="text/javascript">
    # Default value is `false`
    default_attr_vals = false

    # To preserve all end tags
    # Default value is `false`
    end_tags = false

Step 4

Congratulations, you have successfully implemented HTML Minify in few seconds.

Spread the word of aah, the web framework for Go. Thank you!