Several improvements in the header contribution functionality have been made in Wicket 6 to make it more flexible.
With the example above Wicket will render first the <script> to load Dojo and the <link> to load a.css before rendering the <script> for my.js.
Another new feature in Wicket 6 is that several resources can be combined together in one before delivering it to the browser.
One way to do this is to use WebApplication's ResourceBundles:
Another way is by extending ConcatResourceBundleReference and using it as any other ResourceReference.
The bundle (with all resources) will be contributed if at least one of its resources is contributed by a component or behavior.
Sometimes a third-party library or even Wicket itself adds dependencies you
would rather replace by something else. For example, your application might
CDN rather than a packaged resource. For this, Wicket 6 supports replacement
resources. A replacement resource is a resource that will replace any
occurence of some other resource throughout the application. It does not
matter if the replaced resource is added in third party code, in your code or
even as a depedency of another resource.
The following code replaces any occurence of DojoResourceReference by the
version hosted on the Google APIs CDN:
Positioning of contributions
This is made a bit simpler now by introducing FilteredHeaderItem.
To make a use of it the developer have to add a special component in his page:
And later contribute FilteredHeaderItems in any component or behavior:
Since Wicket 1.5 components do their header contribution before the page they are contained in. The reason is that the application may use a third party component library and the page should be able to override any contribution made by the components. A better design is if the components may be configured what to contribute but sometimes this is not possible. The same is valid for component inheritence - the specialization (the child component) contributes after the base component.
Thanks to the HeaderItems with Wicket 6 it is possible to give some header contributions bigger priority than the others when there is such need. By default Wicket provides PriorityHeaderItem which is an item that is contributed before any other non-priority item. If the application needs finer control then it may register a custom comparator with IResourceSettings#setHeaderItemComparator(Comparator)
A demo application showing all these features in action can be found at Martin Grigorov's GitHub repository. Run it locally and check the produced markup for the pages. There are comments inside the code describing the demonstrated features.
Additionally the Resource aggregation example has been updated to use the new features.