Skip to content

Htmlcompressor

akiraly edited this page Sep 7, 2011 · 1 revision

Html Compressor Project

About

WicketStuff Htmlcompressor is an integration library for wicket and htmlcompressor. It can be used to minify (compress) the html markup. Minifying the html markup (together with gzip) can improve speed rendering, server troughput and lower bandwith usage.

Maven snippet

Add this to your pom.xml:

<dependency>
	<groupId>org.wicketstuff</groupId>
	<artifactId>wicketstuff-htmlcompressor</artifactId>
	<version>[some-version]</version>
</dependency>

Usage

Register a HtmlCompressingMarkupFactory in wicket:

public class HtmlCompressorApp extends WebApplication
{
	@Override
	protected void init()
	{
		super.init();
		if (usesDeploymentConfig())
		{
			getMarkupSettings().setMarkupFactory(new HtmlCompressingMarkupFactory());
			// if we want custom settings for our compressor we could do this instead:
			// HtmlCompressor compressor = new HtmlCompressor();
			// compressor.setPreserveLineBreaks(true);
			// getMarkupSettings().setMarkupFactory(new HtmlCompressingMarkupFactory(compressor));
		}
	}

	@Override
	public Class<? extends Page> getHomePage()
	{
		return HomePage.class;
	}
}

And done. Now in deployment mode the html markup will be minified.

Htmlcompressor

Htmlcompressor can be customized with a lot of different options. If enabled it can minify javascript and css blocks inlined in the html too. For more info see the htmlcompressor documentation.

Dependencies

Wicketstuff-htmlcompressor depends only on wicket 1.5-RC7<= and htmlcompressor 1.4.

Further reading

For more info see the javadoc of the classes. For a complete example see the wicketstuff-htmlcompressor-examples web application.

Clone this wiki locally