在PWA(离线)中启动WebGL

发布于 2025-02-05 02:43:44 字数 946 浏览 3 评论 0原文

我正在开发PWA(具有非常基本的香草JS),即使用户离线也是如此,也尝试在其中进行Unity WebGL启动。 我已经将所有文件都放在缓存上,但仍然不起作用。 我是这个野生动物,所以我对此表示感谢。 这是我的服务工人文件的内容:

const cacheName = "static"
const appFiles = [
    "./",
    "xmlhttprequest-length-computable.min.js?v=1.5.1.22060315",
    "images/favicon.ico",
    "images/icon.png",
    "style.css",
    "responsiveMinimalTemplateStyles.css",
    "responsiveMinimalTemplateLoader.js",
    "manifest.json",
    "Build/WebGL.loader.js",
    "Build/WebGL.framework.js",
    "Build/WebGL.data",
    "Build/WebGL.wasm"
]
self.addEventListener("install", e => {
    console.log('Install')
    e.waitUntil(
        caches.open(cacheName).then(cache => {
            return cache.addAll(appFiles)
        })
    )
})

self.addEventListener("fetch", e => {
    e.respondWith(
        caches.match(e.request).then(response => {
            return response || fetch(e.request)
        })
    )
}) 

有什么想法吗?

I am working on a PWA (with very basic vanilla JS) and i try to make a unity webGL launch in it even when the user is offline.
I have put all of my files on cache but it still does not work.
I'm a begginer in this so i'll be very thankfull for any help on this.
Here is the content of my service-worker file :

const cacheName = "static"
const appFiles = [
    "./",
    "xmlhttprequest-length-computable.min.js?v=1.5.1.22060315",
    "images/favicon.ico",
    "images/icon.png",
    "style.css",
    "responsiveMinimalTemplateStyles.css",
    "responsiveMinimalTemplateLoader.js",
    "manifest.json",
    "Build/WebGL.loader.js",
    "Build/WebGL.framework.js",
    "Build/WebGL.data",
    "Build/WebGL.wasm"
]
self.addEventListener("install", e => {
    console.log('Install')
    e.waitUntil(
        caches.open(cacheName).then(cache => {
            return cache.addAll(appFiles)
        })
    )
})

self.addEventListener("fetch", e => {
    e.respondWith(
        caches.match(e.request).then(response => {
            return response || fetch(e.request)
        })
    )
}) 

Any ideas ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2025-02-12 02:43:44

好的,我是新手,所以如果可以帮助任何人,我会在这里回答自己。
终于在这里找到了我的答案(当然必须将其适应我自己的代码):
渐进式网络应用程序(在Promise)typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:typeerror:提取

必须完成我的self.addeventlistener(“ fetch”,请求:

self.addEventListener("fetch", e => {
 e.respondWith(
     caches.match(e.request).then(response => {
         if(response){
             console.log('[Service Worker] Récupération de la ressource: '+e.request.url);
             return response
         } else {
             return fetch(e.request).then((response) => {
                 return caches.open(cacheName).then((cache) => {
                     console.log('[Service Worker] Mise en cache de la nouvelle ressource: '+e.request.url)
                     cache.put(e.request, response.clone())
                     return response
                 })
             })
         }
     })
 )
})      

Ok i'm new to this so i'll be answering myself here, if it can help anybody another time.
Finally found my answer here (and of course had to adapt it to my own code) :
Progressive web app Uncaught (in promise) TypeError: Failed to fetch

Had to complete my self.addEventListener("fetch", request :

self.addEventListener("fetch", e => {
 e.respondWith(
     caches.match(e.request).then(response => {
         if(response){
             console.log('[Service Worker] Récupération de la ressource: '+e.request.url);
             return response
         } else {
             return fetch(e.request).then((response) => {
                 return caches.open(cacheName).then((cache) => {
                     console.log('[Service Worker] Mise en cache de la nouvelle ressource: '+e.request.url)
                     cache.put(e.request, response.clone())
                     return response
                 })
             })
         }
     })
 )
})      
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文