简体   繁体   English

HTML5“收藏夹”离线缓存

[英]HTML5 `favorite` offline caching

I'm currently building an application with which you can create playlists of song lyrics and cache them for use offline. 我目前正在构建一个应用程序,您可以使用该应用程序创建歌词的播放列表并将其缓存以供离线使用。 You can also cache your favorites (JSON array). 您还可以缓存收藏夹(JSON数组)。

Now, because the favorites are cached - the add favorite button doesn't work in the client side. 现在,由于收藏夹已缓存- add favorite按钮在客户端不起作用。 Yes, it does save the favorite on the server side, but there are no changes in the client side. 是的,它确实将收藏夹保存在服务器端,但是客户端没有任何更改。

What would you suggest me to do in order to fix this issue? 您建议我做什么来解决此问题? Is re:downloading the cache on every single add favorite click the only thing I can do, or perhaps there's another way how I could resolve this? re:在每个add favorite单击上都下载缓存是我唯一能做的,或者也许还有另一种方法可以解决此问题?

Please note that I do know how to update the cache . 请注意, 我确实知道如何更新缓存 I'm just wondering if there's a better way how to fix this problem. 我只是想知道是否有更好的方法来解决此问题。

Thanks! 谢谢!

Ill assume you need to update your HTML5 application cache through Javascript, in that case this guide should explain everything you need to know: http://www.html5rocks.com/en/tutorials/appcache/beginner/ 假设您需要通过Javascript更新HTML5应用程序缓存,在这种情况下,本指南应说明您需要了解的所有信息: http : //www.html5rocks.com/zh_CN/tutorials/appcache/beginner/

What you could do is use a listener to monitor the updateready event on page load. 您可以做的是使用侦听器监视页面加载时的updateready事件。 Snippet from the above guide: 以上指南的摘录:

// Check if a new cache is available on page load.
window.addEventListener('load', function(e) {

  window.applicationCache.addEventListener('updateready', function(e) {
    if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
      // Browser downloaded a new app cache.
      // Swap it in and reload the page to get the new hotness.
      window.applicationCache.swapCache();
      if (confirm('A new version of this site is available. Load it?')) {
        window.location.reload();
      }
    } else {
      // Manifest didn't changed. Nothing new to server.
    }
  }, false);

}, false);

As you updated your question stating that you know how to update your cache, ill also update my answer. 当您更新问题以至于您知道如何更新缓存时,我也将更新我的答案。 Html5 appcache is designed to download everything, and there is no "fix" for your problem - this is how it is designed. Html5 appcache旨在下载所有内容,并且没有针对您的问题的“修补程序”-这就是它的设计方式。 Now if you are looking for alternative solutions you might want to ask a new question. 现在,如果您正在寻找替代解决方案,则可能要问一个新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM