petrbroz / forge-disconnected

Sample Forge application using Service Workers and Cache APIs to provide a limited offline support.
https://forge-disconnected.autodesk.io
18 stars 11 forks source link
autodesk-forge express nodejs service-worker

forge-disconnected

Sample Autodesk Forge application using Service Workers and Cache APIs to provide a limited offline support, allowing you to cache selected models and view them without internet connection.

Live demo is available at https://forge-disconnected.autodesk.io.

Running locally

Debugging

In Chrome, the Application tab of the DevTools provides many useful tools for working with service workers. The Service Workers section shows any running workers, provides links to their source code, and allows you to update or unregister them. In the Cache Storage section you'll find the cache objects associated with the corresponding site.

Chrome - Service Workers Chrome - Cache Objects

In Firefox, you can use the about:serviceworkers or about:debugging#workers URL to get a detailed information about service workers currently registered for various websites.

Firefox - Service Workers

Caching strategy

Static assets and known APIs are cached immediately when the service worker is installed, see the STATIC_URLS and API_URLS constants in the worker script.

Note that in our case we only cache a subset of the viewer's assets, e.g., only two environments are cached: Sharp Highlighs and Boardwalk. If you want to include other static assets, perhaps including your own viewer extensions, don't forget to include them in the list.

A single document in Forge typically generates multiple derivatives, and derivatives themselves often reference additional assets. We need a way to identify these assets in order to cache them when needed. In this sample application, the server provides a GET /api/models/:urn/files endpoint which is inspired by https://extract.autodesk.io and - given a document URN - provides a list of URLS for all derivatives and their assets.

Known issues & gotchas