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.
<dependency> <!-- changed groupId to at.molindo --> <groupId>at.molindo</groupId> <artifactId>wicketstuff-merged-resources</artifactId> <version>3.1-alpha-1</version> </dependency>
Then simply replace ResourceMount with RemoteHostResourceMount:
ResourceMount mount = new RemoteHostResourceMount("http://cdn.example.org/") .setResourceVersionProvider(new RevisionVersionProvider()) .setPath("/style/all.css") .addResourceSpecsMatchingSuffix(PanelOne.class, ComponentB.class, MyForm.class) .mount(this);
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("http://cdn.example.org"); 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.