• Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Java and Wicket web development thoughts, tutorials, and tips

roman@coderdreams.com
Coder DreamsCoder Dreams
  • Fat Cats Boardgame
  • Wicket UI Library
  • About Me

Reducing Wicket page size part 1: Using the Literal component

September 12, 2019 Posted by Roman Sery performance, wicket No Comments

Wicket page size

One of the most important things you need to keep an eye on when developing Wicket apps is the page size. Not the size of the HTML that is sent to the browser, we are talking about the size of all the models, objects, and classes that Wicket creates.

All of these objects get serialized into session when the Page version is saved; such as when you update something on the page via an AJAX request. The impact is exaggerated when you are using a session provider such as Redis, which requires network round-trips.

Reducing page size using Literals

There are many techniques we can use to reduce page size. We will discuss one here which is the Literal Component that can be used in place of Labels:

public class Literal extends Component {
    private static final long serialVersionUID = 1L;
    private transient String lbl;
    public Literal(String id, String lbl) {
        super(id);
        this.lbl = lbl;
    }

    @Override
    public void onConfigure() {
        super.onConfigure();
        setEscapeModelStrings(false);
        setRenderBodyOnly(true);
    }

    @Override
    protected void onRender() {
        if(!StringUtils.isBlank(lbl)) {
            getResponse().write(lbl);
        }
    }
}

You can see that Literal relies on a transient String which never gets serialized and it creates no other components. It simply writes the String to the response body without needing to store a Model. A Label, whether you pass a String or a Model, needs to store a Model.

How to observe the difference in page size

We can easily create a test page to observe this difference in page size. I won’t include the full code here, but you can see it on GitHub. We create a page with a ListView that renders 100 items, each displaying a random String of 100 characters.

Results:

Label with Model: 101 KB

Label with LoadableDetachableModel: 54 KB

Literal: 48 KB

When to use Literal

Literals are good for replacing Label’s inside of ListView’s or in any place that requires a dynamic String to be displayed that doesn’t need to be updated via AJAX.

You will still need to use Label’s when doing AJAX updates because a Literal doesn’t create any Components or Model objects and only renders it’s transient value during page render.

However there are a lot more use cases for Literal that will net you even more size savings. You can replace BookmarkableLink’s, Images, etc. Of course you should use Literal’s sparingly only when you’re dealing with large pages where performance is critical.

Good luck reducing your Wicket page sizes! I will blog about other ways to do it in the future.

No Comments
Share
2

About Roman Sery

I've been a software developer for over 10 years and still loving Java!

You also might be interested in

How to replace PropertyModel with Wicket 8 LambdaModel

Aug 23, 2019

Learn how to replace the loved/hated PropertyModel with the much sexier LambdaModel.

Creating secure encrypted links in Wicket with Apache Shiro

Nov 16, 2019

Quickly get started creating secure encrypted links in your Wicket application!

Creating single click buttons with Wicket

Aug 16, 2019

How to create a Wicket button component to prevent users from clicking buttons multiple times in succession.

Categories

  • aws
  • customization
  • database
  • debugging
  • enum
  • java
  • models
  • performance
  • projects
  • react
  • software design
  • Spring
  • tool
  • Uncategorized
  • wicket

Recent Posts

  • Rent Day
  • Self-contained Wicket Fragments
  • Pros and cons of unit testing
  • Themeable React Monopoly board
  • Please dont use client-specific release branches

Recent Comments

  • TCI Express Thanks for sharing such insightful information. TCI Express truly stands out as the best air logistics company, offering fast, secure, and efficient air express and cold chain transportation services....

    Tracking down a bug in production Wicket application ·  March 25, 2025

  • Tom Error: A zip file cannot include itself Can you please correct the plugin part so it doesn't use the same folder as input?

    Deploying Spring Boot app to AWS Beanstalk with Nginx customization ·  September 3, 2021

  • Golfman: Reality always wins I've used both Wicket and front-end JS frameworks and, having worked extensively on both, I can tell you that "Speed of development" is definitely NOT with the JS frameworks. You basically end up...

    Five reasons you should use Apache Wicket ·  August 29, 2021

  • Kiriller Sorry can not agree with you, wicket might be a well built technical framework. But the advantages of using a front-end framework like react.js and vue.js can not be beaten by Wicket nowadays. - Speed...

    Five reasons you should use Apache Wicket ·  August 23, 2021

  • Bernd Lauert Sorry but i have to refute your claims with the following arguments: 1. the Wicket community may be small but it is also very responsive, you usually get a helpful answer from the core devs on the...

    Five reasons you should use Apache Wicket ·  July 1, 2021

Archives

  • May 2021
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019

Contact Me

Send Message
Prev Next