public class OfflineCache extends Object
List 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);
To contribute the offline cache use the following snippet in the renderHead method of a page:
OfflineCache.renderHead(response);
If the cache name is going to be changed all resources are going to be reloaded again. This happens
if the browser loads the new service worker content (after a browser refresh). The new service
worker is going to be initialized as "waiting". (See chapter "How to Update a Service Worker" of
the html5 rocks article) If you then switch the page to google for example and switch back, the
new content is going to be shown up and the old service worker is going to be marked as
"REDUNDANT". You have to leave the page with ALL tabs! Wicket handles older caches to be invalid
and clear them - so when you switch from "MyCache-1" to "MyCache-2" all entries of "MyCache-1"
are going to be cleared.| Constructor and Description |
|---|
OfflineCache() |
| Modifier and Type | Method and Description |
|---|---|
static List<OfflineCacheEntry> |
getOfflineCacheEntries(WebApplication application)
Gets the offline cache entries
|
static void |
init(WebApplication webApplication,
String cacheName,
List<OfflineCacheEntry> offlineCacheEntries)
Initializes the offline cache (used in the init method of a wicket application)
|
static void |
renderHead(IHeaderResponse response)
Loads the service worker registration and the service worker implementation java script
references
|
static void |
setOfflineCacheEntries(WebApplication application,
List<OfflineCacheEntry> offlineCacheEntries)
Sets the offline cache entries (can only be used if the offline cache hasn't been initialized
yet)
|
public static void init(WebApplication webApplication, String cacheName, List<OfflineCacheEntry> offlineCacheEntries)
webApplication - the web application to mount the offline cache referencescacheName - the cache nameofflineCacheEntries - the offline cache entries to be cachedpublic static void renderHead(IHeaderResponse response)
response - the response to contribute the offline cache referencespublic static List<OfflineCacheEntry> getOfflineCacheEntries(WebApplication application)
public static void setOfflineCacheEntries(WebApplication application, List<OfflineCacheEntry> offlineCacheEntries)
application - the application instanceofflineCacheEntries - the offline cache entries to storeCopyright © 2020. All rights reserved.