提取服务工人

时间:2018-11-19 09:46:23

标签: service-worker autodesk-forge autodesk-viewer autodesk-data-management service-worker-events

嗨,我正在尝试使用Autodesk Forge Viewer创建服务工人,安装 ACTIVATE 可以工作,但无法获取。

这是我的服务人员

    const cacheName = 'v1';

const cacheAssets = [
    "/index.html",
    "/css/main.css",
    "/img/myAwesomeIcon.png",
    "/js/ForgeTree.js",
    "/js/ForgeViewer.js",
    "/js/myawesomeextension.js",
    "/js/sw.js",
];


self.addEventListener('install', e => {
    console.log('service worker: installed');

    e.waitUntil(
        caches 
            .open(cacheName)
            .then(cache => {
                console.log('service worker: caching files');
                cache.addAll(cacheAssets);
            })
            .then(() => self.skipWaiting())
    );
});

self.addEventListener('activate', e => {
    console.log('service worker: activated');
    e.waitUntil(
        caches.keys().then(cacheNames => {
            return Promise.all(
                cacheNames.map(cache => {
                    if(cache !== cacheName) {
                        console.log('service worker: clearing old cache');
                        return caches.delete(cache);
                    }
                })
            );
        })
    );
});

self.addEventListener('fetch', e => {
    console.log(e);
});

我正在尝试制作自己的“已断开连接的工作流程”,以获取帖子并缓存所有模型,以从bim360docs,a360并使用2leg forge教程离线查看它们。

1 个答案:

答案 0 :(得分:0)

尝试使用浏览器提取API提取任何内容:

fetch('http://example.com/movies.json')
  .then(function(response) {
    return response.json();
  })
  .then(function(myJson) {
    console.log(JSON.stringify(myJson));
  });

https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API