New this build: new offline support using Service Workers!
Changes in offline support
For a long time Construct 2 games have been able to run offline using a browser technology called AppCache. This is more or less a text file with a list of URLs to save (appearing as offline.appcache in your exports). However AppCache is generally regarded as a mistake, and browser makers are starting to begin a long-term process of dropping support for it. A new and more powerful technology called Service Worker is being developed to replace AppCache for offline support, as well as being capable of other background services like background sync, push notifications, and geofencing (much of which is still in development).
Service Workers are currently only supported in Chrome and Firefox, although it's in development for Edge and is under consideration for Safari. It is likely that in the long-term all browsers will support Service Workers and ultimately AppCache will be removed, so the transition is inevitable.
Offline support with Service Worker
The new offline support is designed to work similarly to AppCache, i.e.:
- The first visit causes the whole game to be saved locally.
- Subsequent visits load entirely from the locally saved copy. Not only does this mean it can load offline, it also loads faster and saves bandwidth since no further server resources are requested.
- When you upload a new version, on the next visit it loads the old version still, but updates to the new version in the background.
- Once the background update has finished, pressing the browser "reload" button will then load the new version. (This means you usually have to reload twice, with enough time in between for the background download to finish.)
Note this only applies to web-based exports. Platforms like Cordova, NW.js and Windows Store apps already load from local resources, so none of this applies to them.
The Service Worker based implementation has some differences to the old AppCache support:
- Service Workers only work on HTTPS. We have warned before that powerful new web platform features will only allowed on HTTPS. If you haven't yet moved to secure hosting, note it is now required for offline support.
- AppCache could slow down the first load of the game, since it would be caching the entire game (such as music files that aren't needed immediately) while the progress bar is showing. The new Service Worker system waits until the game finishes loading before starting to save a local copy, so it shouldn't slow down the first load.
- In Chrome, it can't update when you press "reload" - you currently have to close and reopen the browser window/tab (hopefully this can be fixed)
- Because the new system works differently to the old one, we've deprecated the Browser plugin's 'Is downloading update" and "On update ready" conditions. These only work with AppCache.
- Like some browsers did with AppCache, the Service Worker will log messages to the browser console indicating if it is up-to-date, downloading an update, ready to update, etc. You should look for these messages if you want to test a new version you've uploaded so you know when it's ready.
Since not all browsers support Service Workers yet, we are still keeping the old AppCache support for the time being! This means:
- Exported games use both AppCache and Service Worker for offline support
- Browsers that support Service Worker will use that and ignore AppCache (except note this bug in Chrome that means it will unintentionally save an AppCache but not use it)
- Browsers that don't support Service Worker will keep using AppCache
Overall, this is a bit complicated, but the transition needs to happen. Due to the various differences and complexities of making the transition we are keen for this to get thorough testing. So if you publish to the web at all, please try exporting your games, playing them once online, going offline (e.g. pull out network cable, disable wifi, etc), then trying to load the game from the same URL again. All being well it should still load and play the same as it did before, even with no connection. Remember if users do "add to homescreen", save shortcuts, or use other features to make a web page more app-like, offline support is particularly important for those cases since users will expect it to act like an app that works offline too.
We'd love it if you could show your appreciation of it by retweeting and sharing it on Facebook and Twitter!