20. HTML5 OfflineMode - klopfdreh/wicket-components-playground GitHub Wiki

User case scenario:

If a user is currently surfing on a web page provided by a web site which uses Apache Wicket as web framework. Now imagine he travels through an area where there is no signal to contact the web server and the user wants just in this moment to navigate to a different page. Without the offline mode the browser would show "no connection" and the user has to wait until he gain a signal again. With the offline mode the user can continue surfing without noticing that there is no signal.

Example Implementation:

In application class:

List<OfflineCacheEntry> offlineCacheEntries = new ArrayList<>();
offlineCacheEntries.add(new OfflineCacheEntry().setCacheObject(new CssResourceReference(HomePage.class, "main.css")));
offlineCacheEntries.add(new OfflineCacheEntry().setCacheObject(HomePage.class));
OfflineCache.init(this, "MyCache-1", offlineCacheEntries);

In a web page (e.g. HomePage.class):

@Override
public void renderHead(IHeaderResponse response)
{
	super.renderHead(response);
	response.render(
		CssHeaderItem.forReference(new CssResourceReference(HomePage.class, "main.css")));
	// You have to ensure the offline cache to be load in each page which should be cached.
	OfflineCache.load(response);
}

The implementation itself uses the "Service Worker"-API of browsers. Have a look into the OfflineCache class to see which browsers are support and how it works:

https://github.com/klopfdreh/wicket-components-playground/blob/master/wicket-components-playground/src/main/java/org/apache/wicket/offline/OfflineCache.java

Available in Wicketstuff Version 7.3.0. Dependency:

Dependency:

   <dependency>
      <groupId>org.wicketstuff</groupId>
      <artifactId>wicketstuff-offline-mode</artifactId>
      <version>/version/</version>
   </dependency>
⚠️ **GitHub.com Fallback** ⚠️