Package org.wicketstuff.offline.mode
Class OfflineCache
java.lang.Object
org.wicketstuff.offline.mode.OfflineCache
The offline cache to initialize / load the client side cache.
Example:
For more information see:
- https://www.w3.org/TR/service-workers/#navigator-service-worker-waiting
- https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
- http://www.html5rocks.com/en/tutorials/service-worker/introduction/
- http://caniuse.com/#search=Service%20Worker
Important: local development can be achieved through HTTP (localhost, 0.0.0.0, 127.0.0.1), with DNS you have to use HTTPS! Service worker only running with HTTPS if not local.
Example:
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);
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.For more information see:
- https://www.w3.org/TR/service-workers/#navigator-service-worker-waiting
- https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API
- http://www.html5rocks.com/en/tutorials/service-worker/introduction/
- http://caniuse.com/#search=Service%20Worker
Important: local development can be achieved through HTTP (localhost, 0.0.0.0, 127.0.0.1), with DNS you have to use HTTPS! Service worker only running with HTTPS if not local.
- Author:
- Tobias Soloschenko
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<OfflineCacheEntry>getOfflineCacheEntries(WebApplication application) Gets the offline cache entriesstatic voidinit(WebApplication webApplication, String cacheName, List<OfflineCacheEntry> offlineCacheEntries) Initializes the offline cache (used in the init method of a wicket application)static voidrenderHead(IHeaderResponse response) Loads the service worker registration and the service worker implementation java script referencesstatic voidsetOfflineCacheEntries(WebApplication application, List<OfflineCacheEntry> offlineCacheEntries) Sets the offline cache entries (can only be used if the offline cache hasn't been initialized yet)
-
Constructor Details
-
OfflineCache
public OfflineCache()
-
-
Method Details
-
init
public static void init(WebApplication webApplication, String cacheName, List<OfflineCacheEntry> offlineCacheEntries) Initializes the offline cache (used in the init method of a wicket application)- Parameters:
webApplication- the web application to mount the offline cache referencescacheName- the cache nameofflineCacheEntries- the offline cache entries to be cached
-
renderHead
Loads the service worker registration and the service worker implementation java script references- Parameters:
response- the response to contribute the offline cache references
-
getOfflineCacheEntries
Gets the offline cache entries- Returns:
- the offline cache entries
-
setOfflineCacheEntries
public 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)- Parameters:
application- the application instanceofflineCacheEntries- the offline cache entries to store
-