GitHub

User guide

Resources

Serve CSS, JavaScript, images and generated files.

How-to guides

Directions for a specific goal.

  • Serve files from your Java packages Keep images, media and other files next to the component that uses them and serve them with PackageResourceReference, from Java or from markup.
  • Add CSS and JavaScript to a page Let a component or behavior add its stylesheets, script files and start-up code to the page header with renderHead and header items.
  • Use files from the web application root Add stylesheets, scripts and images that live in the web application folder, such as src/main/webapp, to your pages with ContextRelativeResourceReference and ContextImage.
  • Declare dependencies between resources Make a script or stylesheet pull in the libraries it needs by overriding getDependencies, so Wicket always renders them first and only once.
  • Combine resources into one bundle Serve several package stylesheets or scripts as one file with ResourceBundles, and replace a resource throughout the application with addResourceReplacement.
  • Put JavaScript at the end of the body Render all script header items in a container just before the closing body tag with JavaScriptFilteredIntoFooterHeaderResponse and HeaderResponseContainer.
  • Control the order of header items Put a header item first with PriorityHeaderItem, let the page's own items come before those of its components, and fix where Wicket inserts items with wicket:header-items.
  • Generate a resource in code Build files on request, such as a CSV export, a PDF or an image, by extending AbstractResource or writing a lambda, and offer them for download with ResourceLink.
  • Give a resource a URL Mount a resource reference on a path of your choice with mountResource, read path and query parameters in the resource, and link to the mounted URL.
  • Share a resource across the application Register a resource once under an application-wide key with getSharedResources and refer to it from any component with SharedResourceReference.
  • Customize where resources are loaded from Make Wicket find markup, properties and package files in a folder of the web application or the file system by adding resource finders.
  • Minify and compress CSS and JavaScript Serve pre-minified .min files, strip JavaScript in deployment mode, plug in your own CSS or JavaScript compressor, and rewrite URLs inside stylesheets with CssUrlReplacer.
  • Serve files with NIO Serve files from the file system or from inside a ZIP archive through java.nio.file.Path with FileSystemResourceReference and FileSystemResource, including byte ranges for media.
  • Show images from an external URL Render img and source tags whose URL comes from a model with ExternalImage and ExternalSource, for images on another server or a CDN.

Reference

The classes, tags and settings, described.

  • Header items Every header item type with its factory methods, the tag it renders and where it ends up, the rendering order, Ajax behaviour and the header response decorators.

Explanation

Why Wicket works the way it does.

  • How Wicket serves resources What resources and resource references are, why components carry their own CSS and JavaScript, and how Wicket gives every file a cacheable URL.