Serving Wicket Resources from CDN

March 16th, 2011 by  |  Published in Java, Wicket, wicketstuff-merged-resources  |  3 Comments

This post is short but still just amazing. Now it’s possible to serve Wicket resources from CDNs supporting custom orgins within just a few minutes (at least if you are already using wicketstuff-merged-resources). First of all, you’ll need the latest version (3.1-alpha-1) of wicketstuff-merged-resources (which is now available from Maven Central!).

If you haven’t already done so, add the dependency and read articles in the wicketstuff-merged-resources category to get started.

  <!-- changed groupId to at.molindo -->

Then simply replace ResourceMount with RemoteHostResourceMount:

ResourceMount mount = new RemoteHostResourceMount("")
  .setResourceVersionProvider(new RevisionVersionProvider())
  .addResourceSpecsMatchingSuffix(PanelOne.class, ComponentB.class, MyForm.class)

And that’s it. Cool, eh? All you have to do now is configuring your CDN to fetch resources from your server. We are using Amazon CloudFront since it supports custom origins. See “Creating a Distribution with a Custom Origin” and “Custom Origins Best Practices” for configuration instructions.

By the way, RemoteHostResourceMount uses RemoteHostUrlCodingStrategy (also part of wicketstuff-merged-resources) internally. This URL coding strategy may easily be used on its own:

ResourceReference ref = new ResourceReference(CssScope.class, "all.css");
URL root = new URL("");
String mountPoint = "/scripts/all.css";
mount(new RemoteHostUrlCodingStrategy(root, mountPoint, ref));

PS: if you haven’t already noticed, wicketstuff-merged-resources (that is source, its admittedly sparse documentation and issues) is now hosted on GitHub.

Have fun!


  1. megalex says:

    October 13th, 2011 at 4:15 pm (#)

    Hi Stefan,

    Wondering when this will be available for wicket 1.5. This looks awesome and would like to try.

  2. Stefan Fußenegger says:

    October 14th, 2011 at 2:57 pm (#)


    There are currently no plans for an upgrade to wicket 1.5. The main reason simply is that too much has changed regarding resource handling. It looks as if a complete rewrite would be the best way to go but that’s just not feasible with my current lack of time. Additionally, we’re basically stuck with 1.4 as a migration seems far too much effort right now. But don’t get me wrong, it’s not a definitive no here, it’s just that there’s nothing planned.

    Cheers, Stefan

  3. thomas willomitzer says:

    January 30th, 2012 at 4:48 pm (#)

    That should work with 1.5 ?

Leave a Response