iOS Web App - 如何处理过度热衷的应用缓存? [英] iOS Web App - how to deal with overzealous app caching?

查看:147
本文介绍了iOS Web App - 如何处理过度热衷的应用缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去一个月我一直在开发一个非常复杂的 HTML5 网络应用。昨晚我的 iPhone 突然决定缓存所有JS,CSS和图像,而不是加载任何更新的副本。这也发生在我的合作伙伴的 iPhone 上,所以我假设它会影响我们应用的所有用户。

I've been developing a pretty complicated HTML5 web app for the past month. Last night my iPhone suddenly decided to cache all JS, CSS, and images and not load any updated copies. This happened on my partner's iPhone too, so I'm going to assume it's affecting all users of our app.

不用说,清除浏览器缓存,删除网络应用程序,重新启动手机,以及重新启动无线连接无需解决问题。

Needless to say, clearing the browser cache, deleting the web app, restarting the phone, & restarting the wireless connection do nothing to fix the problem.

删除< meta name =apple-mobile-web-app-capable内容=是> 解决了问题,但由于我们需要应用程序像...一样运行,因此会产生新问题。

Removing <meta name="apple-mobile-web-app-capable" content="yes"> solves the problem, but creates a new problem since we need the app to run like...an app.

我们不打算将旧技巧?number 附加到我们所有脚本,样式表和图像的末尾。这是荒谬的。另外 - 如果我们 实现类似的东西,它必须是某种动态的JS实现。我们的应用程序是一个加载大多数脚本的HTML页面,其他页面是AJAX,其他数据也是通过AJAX获得的。我想这可以做到,但我希望有一个更优雅的解决方案。我知道,我觉得我不应该做任何事情因为这一切都顺利完成了整整一个月。

We're not going to go around appending the old trick ?number to the end of all our scripts, stylesheets, and images either. That's ridiculous. Also -- if we were to implement something like this, it would have to be some sort of dynamic JS implementation. Our app is one HTML page that loads most scripts, and additional pages are AJAXed in, additional data is also obtained via AJAX. I guess this could be done, but I'm hoping for a more elegant solution. Ya know, I feel like I shouldn't have to do anything since this all worked without a hitch for an entire month.

使用缓存控制到期,以及 pragma < meta> 标签对我们没有好处,因为这纯粹是iOS网络应用程序的问题。缓存通常适用于移动版Safari,移动版Chrome和所有桌面浏览器。似乎iOS有一个单独的应用程序缓存,包括用户无法清除的Web应用程序。

Using the cache-control, expires, and pragma <meta> tags doesn't do us any good either, as this is purely an iOS web app problem. Caching works normally in mobile Safari, mobile Chrome, and all desktop browsers. It appears that iOS has a separate cache for apps, including web apps, that the user can not clear.

似乎很多SO用户都遇到过这个问题,但我找不到任何满意的解决方案。有没有人在类似的情况下解决了这个问题?我可以使用清单文件指定来缓存多个文件吗?似乎清单文件用于做相反的事情。

It seems that many SO users have encountered this problem, but I can't find any satisfactory solutions. Has anyone out there in a similar situation solved this problem? Could I use a manifest file to specify not to cache several files? It seems like manifest files are used to do the opposite.

推荐答案

对于它的价值,它不是一个完美的解决方案,我们不得不解决附加的查询字符串。我编写了一个shell脚本来使这个和其他一些任务更加自动化,你可以在 GitHub的的。一些细节:

For what it's worth, and it's not a perfect solution, we had to settle with appending query strings. I've written a shell script to make this and a few other tasks bit more automated, you can look at the source on GitHub. A few details:


  • 它是专为JS设计的,但也可以轻松编辑以处理CSS。

  • 它需要 script_order.txt 中列出的所有文件,并使用Google的Closure Compiler编译它们

  • 尽可能将它们分组为25kb以下的块( iPhone不会缓存任何超过25kb pre-gzip的东西,虽然这显然只扩展到浏览器而不是独立的webapps)

  • 输出一个带有< script>的PHP文件。 ?v = timestamp 附加到脚本文件名的标记。如果您正在使用静态HTML并且不能包含PHP文件,则可以重写输出以将脚本标记附加到index.html文件。

  • It's designed for JS but can easily be edited to handle CSS too.
  • It takes all files listed in script_order.txt and compiles them with Google's Closure Compiler
  • Groups them into chunks under 25kb when possible (iPhone won't cache anything over 25kb pre-gzip, although apparently this extends only to browsers and not standalone webapps)
  • Outputs a PHP file with <script> tags that have a ?v=timestamp appended to the script filenames. If you're working with static HTML and can't include a PHP file, you could rewrite the output to append the script tags to your index.html file.

另一个非常糟糕的解决方案是使用 .php 文件扩展名保存你的JS / CSS,并在这些文件中将标题设置为这样的:

Another pretty hacky solution would be to save your JS/CSS with a .php file extension, and in those files set the headers to something like this:

<?php
header("content-type: application/javascript");
header('Cache-Control: no-cache');
header('Pragma: no-cache');
?>
window.alert('hello world');

编辑:

将日期设置为将来的2,3或4天,从主屏幕启动应用程序,然后将日期设置回正常也可以做到这一点。

Setting the date to 2, 3 or 4 days in the future, start the app from homescreen and then set the date back to normal also can do the trick.

这篇关于iOS Web App - 如何处理过度热衷的应用缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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