是否可以在白金服务工作人员上进行dom-repeat? [英] Is it possible to combine a dom-repeat on a platinum service worker?

查看:91
本文介绍了是否可以在白金服务工作人员上进行dom-repeat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为用户提供通过分组(书籍的类别,个别书籍,或者如果他们不希望整本书的某些章节,甚至只是章节)来缓存多达2600多个项目的功能.据我所知,不可能对所有这些项目进行预缓存,因为其中有2600多个,并且将来还会更多-服务工作者将超时几百次.而且由于服务人员在安装时要么全部获得要么一无所获(如果我理解正确),我是否需要使用多个服务人员(具有不同的ID?),还是我在考虑这个错误? ?

I want to provide a user the ability to cache up to 2,600+ items, by groupings (categories of book, individual books, or possibly even just chapters of a certain book if they don't want the whole book). It is not possible, as far as I can tell, to precache all of these items because there are 2,600+ of them, and will be more in the future - the service worker will timeout with under a couple hundred. And since service workers either get all or none on install (if I understand correctly), do I need to use multiple services workers (with different ids?), or am I thinking about this wrong?

我在想什么...

<iron ajax></iron-ajax>
<template is="dom-repeat" items="...">
<platinum-sw-register auto-register clients-claim skip-waiting>
    <platinum-sw-cache default-cache-strategy="fastest"
        cache-config-file="../someGenerator.php"></platinum-sw-cache>
</platinum-sw-register>

换句话说:

  1. 通过iron-ajax获取所需的URL列表(基于用户启用缓存的内容)
  2. 通过dom-repeat遍历URL作为组
  3. 使用URL组的自定义缓存配置创建服务工作者
  4. 重复2和3直到完成,然后举杯祝酒

someGenerator.php将为特定的URL组返回JSON配置设置.

That someGenerator.php would return a JSON config setup for the particular group of URLs.

我的应用程序是一个单页应用程序-带有霓虹动画页面-一页代表类别,一页代表图书清单,一页代表每本书的目录,然后每章内容之一.所有数据都是通过Iron-ajax获取的.

My app is a single page app - with neon-animated-pages - one page representing categories, one for book listings, one for table of contents for each book, and then one of each the chapter contents. All of the data is obtained via iron-ajax.

以下是一些说明问题的链接:

Here are some links to demonstrate the issues:

该应用

生成的大型非功能性缓存配置

我怀疑,为了不因冗余而导致服务人员错误或覆盖现有缓存,我将需要分配单独的ID,并将其包含在生成的缓存配置中. 听起来不错吗?

I suspect, in order to not have service workers errors due to redundancy, or overwrite existing caches, I will need to assign individual ids, and include them in the generated cache-configs. Does that sound right?

推荐答案

不,我认为这不是正确的方法. <dom-repeat>并创建多个服务人员无法完成您想要的事情.

No, I don't think that's the right approach. <dom-repeat> and creating multiple service workers isn't going to accomplish what you want.

由于在获取JSON配置和执行所有预缓存方面的延迟,您的确在install处理程序中遇到了一些服务工作者施加的超时.退后一步,确定要整套URL预先缓存吗?

It does look like you're bumping into some service worker-imposed timeouts during your install handler due to the delays in fetching the JSON configuration and performing all of the precaching. Taking a step back, are you sure that you need that entire set of URLs precached?

<platinum-sw>还将为您提供运行时缓存,以便在有可用的网络连接时浏览器加载给定URL时,资源将自动添加到缓存中,并在后续回访期间脱机使用.

<platinum-sw> will give you runtime caching as well, so that when a browser loads a given URL when there's a network connection available, the resources will be automatically added to the cache and available offline during subsequent return visits.

还有其他方法可以使用window.caches从受控页面内缓存资源,也可以使用

There are other approaches that would use either window.caches to cache resources from within your controlled page, or using something like postMessage() to communicate a list of additional URLs to cache from your controlled page to your service worker. Both of those approaches would involve going beyond the default functionality you get from using <platinum-sw> and digging into the internals a bit.

这篇关于是否可以在白金服务工作人员上进行dom-repeat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆