移动网络应用程序无法正确清除缓存

发布于 2024-12-18 16:46:46 字数 424 浏览 3 评论 0原文

我一直在为 iPad 开发移动网络应用程序,但在测试代码时遇到了问题。

有时,iPad 会停止正确更新我编写的所有 JS 库,这似乎是随机的。更新一些代码并发布更改后,我会注意到一些文件已正确更新,而其他文件则没有。在多次缓存清除、电源循环和 WiFi 切换后,此行为仍然存在。

如果我在 Safari 中加载该应用程序,我没有任何问题,但是当我从应用程序的主屏幕图标加载时,问题再次出现。我已经完成了简单的测试,例如向库添加一条警报线,并且该警报在除移动网络应用程序窗口之外的任何地方都不会出现问题。然后,看似随机,问题就消失了,有时需要 5 分钟,有时需要一个小时。

无论应用程序是否使用清单文件,我都会看到此行为。我还尝试通过更新清单文件来刷新这些遗留文件,以强制重新缓存,但问题仍然存在。

有谁知道这是否是 iPad 的已知问题?我可以做些什么来解决这个问题吗?

I've been developing a mobile web app for iPad and I've been running into an issue while testing my code.

Occasionally, and seemingly at random, the iPad will stop properly updating all of the JS libraries I've written. After updating some code and posting the changes, I will notice some files will have properly updated while others have not. This bahavior persists after numerous cache clears, power cycles, and wifi toggles.

If I load the app in safari i have no issues with it, but when I load from the app's homescreen icon the problem re-appears. I've done simple tests like adding an alert line to a library and that alert fires without issue anywhere except within the mobile-web-app window. Then, seemingly at random again, the problem is disappears, sometimes it takes 5 minutes, sometimes it takes an hour.

I see this behavior regardless of whether the app is using a manifest file or not. I have also tried to flush these legacy files by updating the manifest file to force the recache that way, but the problem still persists.

Does anyone know if this is a known issue with iPad? Is there anything on my end that can be done to address this?

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

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

发布评论

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

评论(10

荒人说梦 2024-12-25 16:46:46

对我来说,解决方案是在所有 Javascript 和 CSS 链接的末尾添加 ?v=1
在另一篇 Stackoverflow 帖子上看到它之前,我已经尝试了所有方法,并且它直接起作用了!是时候了...

For me, the solution is adding ?v=1 at the end of all your Javascript and CSS links.
I've tried everything before seeing that on another Stackoverflow post and it worked directly !!! It was about time...

荒岛晴空 2024-12-25 16:46:46

我得到了解决方案!

但首先出现的问题是:iPad 和 iPhone 在打开应用程序时不会刷新缓存。即使删除应用程序、清除 safari 缓存、重新启动设备等也不起作用。

这就是解决方案...taadaa!

您的清单文件必须更改。如果更改,iPad/iPhone 将重新加载缓存。因此,只需在清单文件中写入一个版本号,并在更改某些内容时更改它:

# Version: 1.2

因此,完整的清单文件可能如下所示:

CACHE MANIFEST

# Version 1.5

NETWORK:
*

CACHE:
index.html
jquery-1.7.2.min.js
images/logo.jpg

它甚至会重新加载未写入清单文件的图像之类的内容。我测试了好几次。

顺便提一句。不要忘记使用 http://manifest-validator.com 检查你的清单文件

我的来源非常酷关于离线 Web 应用程序:http://gregsramblings.com/2012/05/28/html5-application-cache-how-to/

它还表示您可能需要启动应用程序两次:

如果清单已更新,浏览器将下载缓存文件列表中的所有文件,但是,此时原始内容已经加载(请记住,它已经缓存,因此加载速度非常快!)。

但它在第一次尝试时总是对我有用。

I got the solution!

But first the problem: iPad and iPhone is not refreshing the cache when opening the app. Even deleting the app, clearing safari cache, restarting device etc. etc. doesnt work.

And here is the solution ... taadaa !

Your manifest-file MUST change. If it is changed, iPad/iPhone will reload the cache. So just write a version number in your manifest file and change it when you changed something:

# Version: 1.2

So a full manifest file could look like this:

CACHE MANIFEST

# Version 1.5

NETWORK:
*

CACHE:
index.html
jquery-1.7.2.min.js
images/logo.jpg

It even reloads things like images that are not written into the manifest file. I tested it a several times.

Btw. dont forget to check your manifest-file with http://manifest-validator.com

My source is this very cool how to about offline web applications: http://gregsramblings.com/2012/05/28/html5-application-cache-how-to/

It also says that you maybe need to start your app twice:

If the manifest was updated, the browser will download all of the files in the cached file list, BUT, the original content will have already loaded at this point (remember that it’s already cached, so it loads super fast!).

But it worked for me always on first attempt.

稀香 2024-12-25 16:46:46

解决这个问题。
添加到 Web 应用程序本身的链接,例如...

<a href="javascript:top.frames.location.reload();">refresh</a>

它的工作原理就像 iPhone/iPad Safari 地址栏上的重新加载按钮!

Work around for this problem.
Add a link to the Web App itself like...

<a href="javascript:top.frames.location.reload();">refresh</a>

It works just like the reload button on the iPhone/iPad Safari address bar!

零度° 2024-12-25 16:46:46

我花了几个小时试图解决这个问题,似乎应该管理文件缓存的清单文件本身可以被缓存,从而使您的网络应用程序陷入困境。

就我而言,我不想缓存任何内容。以下是我解决该问题的方法:

  • 在我的服务器上启用 mod_expires Apache 模块
  • 在与索引文件相同的目录中创建一个 .htaccess 文件。该文件应包含行 ExpiresDefault A1

这告诉服务器每个文件应该在访问后一秒过期。我的网络应用程序被用作学生大会上的一项调查,因此一次只有一个人在使用它。我的解决方案适合我;您可能需要进一步调整它以适合您。

过去,这个问题似乎是随机出现的。我最近的所有测试都表明它的响应符合人们的预期。

I spent several hours trying to fix this problem, and it seems as though the manifest file that is supposed to manage file caching, can itself be cached, leaving your web-app in limbo.

In my case, I didn't want anything cached. Here's how I solved the problem:

  • Enable the mod_expires Apache module on my server
  • Create a .htaccess file in the same directory as the index file. The file should contain the line ExpiresDefault A1.

This tells the server that every file should expire one second after it was accessed. My web-app is used as a survey at student conventions, so only one person is using it at a time. My solution works for me; you might need to tweak it further so it suits you.

In the past, this problem had presented itself seemingly at random. All of my recent testing has shown it to respond as one would expect.

羁绊已千年 2024-12-25 16:46:46

我无法验证缓存是否已正确清除,但这对我有用:

为此,您需要在 iOS 设备上允许 Web Inspector。
转到设置>野生动物园>高级> Web Inspector(它必须处于活动状态)
并且您必须激活计算机 Safari 上的开发者菜单。
转到首选项>高级>激活开发者菜单

  1. 使用 USB 数据线将您的设备连接到计算机
  2. 转到 safari >发展历程>>您的设备名称 >检查应用程序(该应用程序必须正在运行)
  3. 这将在您的计算机上打开 Web 应用程序的检查器
  4. 当检查器打开时 清除缓存(command + alt + E)
  5. 在检查器仍然打开的情况下刷新计算机上的页面( command + R)

不知何故,Web应用程序缓存被清除,我得到了非缓存代码。

I can't verify the cache being cleared properly but this worked for me :

In order to do this, you need to allow Web Inspector on your iOS device.
Go to Settings > Safari > Advanced > Web Inspector (it has to be active)
And you have to activate the developer menu on your computer's Safari.
Go to Preferences > Advanced > Activate Developer menu

  1. Connect your device to your computer with the USB cable
  2. Go to safari > Developpement > Your Device name > Inspect an App (The app has to be running)
  3. This will open The inspector on your computer for the web app
  4. While the inspector is open Clear the cache (command + alt + E)
  5. With the inspector still open refresh the page on your computer (command + R)

Somehow the Webapp cache got cleared and i got the non-cached code.

叹梦 2024-12-25 16:46:46

我在 iPad 上的 Web 应用程序遇到了完全相同的问题 - 有时,在独立模式下运行的 Web 应用程序随机不会刷新特定资源(HTML/CSS/JS 文件),尽管杀死了所有可能的应用程序,清除Safari 缓存和历史记录、重新启动、重新启动 wifi 连接、刷新或删除 manifest 文件或将设备放入微波炉中;即使使用大锤也被证明是徒劳的。

虽然我还没有找到“彻底”的方法来修复它,但总有一个解决方法 - 重命名资源。

只需更改不刷新文件的名称即可。如果您遇到 foobar.js 未更新的问题,请将其重命名为 foobar2.js更新对此资源的引用在其他文件中。这当然可能是一个痛苦你知道吗(特别是在经过一周的开发后你在foobar12.js),但是直到我们看到官方修复iOS 或一种可行的刷新技术,这是我所知道的启动和运行它的唯一方法。

I'm having exactly the same problem with my web applications on iPad - sometimes, at random, the web app run in standalone mode wouldn't refresh a particular resource (HTML/CSS/JS file), despite killing every possible app, clearing Safari cache & history, rebooting, restarting wifi-connection, refreshing or removing the manifest file or putting the device in a microwave; even applying a sledgehammer proved to be futile.

While I haven't found a "kosher" way to fix it, there is always a workaround - rename the resource.

Simply change the name of the not-refreshing file. If you have a problem with, let's say, foobar.js not updating, rename it to foobar2.js and update the references to this resource in other files. This of course could be a pain in you know what (especially when after a week's worth of development you are at foobar12.js), but until we see an official fix to iOS or a working refreshing technique, it's the only way I know of to get it up and running.

始于初秋 2024-12-25 16:46:46

关闭和打开ipad对我来说很有效——至少在ios 5上是这样。不是完全关闭,只需使用ipad顶部的睡眠按钮,然后使用主页按钮将其重新打开。在文件末尾附加版本号也可以,但这会变得非常乏味。

turning the ipad off and on works for me - at least on ios 5. not completely off, just use the sleep button on the top of the ipad and then the home button to turn it back on. appending a version number at the end of files also works, but that gets quite tedious.

南薇 2024-12-25 16:46:46

我花了很多天的时间来解决这个问题。它看起来像是一个渲染错误,因为我在 CSS 和 HTML 中做了一些巧合的更改,因此将按钮放在屏幕上的随机位置,导致应用程序无法使用。

经过几天的摸索和刺激,我确定 CSS 已被缓存,最后尝试重命名文件,这是@Neo 谈到的。我还更改了 .htaccess 文件中的缓存控制,因为我一直使用旧的 .htaccess 指示浏览器缓存一年。

tl;dr:删除缓存控制(mod_expiresmod_headers) 用于您的 web 应用程序文件,只需使用 缓存清单(如果您还没有)。然后重命名文件并更新 HTML 中的链接,这样就可以了。

I spent many days working on this problem. It looked like a rendering bug because of some coincidental changes I had made in both CSS and HTML, thus putting buttons at random places on the screen rendering the app unusable.

I determined that the CSS was cached, after several days of poking and prodding, and finally tried renaming the files, something @Neo talks about. I also changed cache-control in my .htaccess file, as I had been using an old .htaccess that instructed the browser to cache for a year.

tl;dr: Remove cache-control (mod_expires and mod_headers) for your webapp files, and just use a cache manifest if you're not already. Then rename the files and update the links in your HTML and you should be good.

≈。彩虹 2024-12-25 16:46:46

我遇到了完全相同的问题。

我在这里尝试了不同的建议,并添加了缓存控制,但没有成功。我尝试重命名拒绝更新的文件,但没有成功。我尝试添加一个缓存清单(我之前有一个,但删除了它),但没有成功。我尝试了所有常见的操作:删除应用程序、清除缓存、重新启动、重新安装应用程序,但没有成功。

唯一对我有用的就是重命名我的网络服务器上的虚拟目录。这可能不是每个人都可行的解决方案,但幸运的是,这并不是真正的问题,因为我正在使用本地 IIS 服务器进行测试。

I had the exact same problem.

I tried the different suggestions here, and added cache control with no luck. I tried renaming the file that refused to update, no luck. I tried adding a cache manifest (I had one before, but removed it), no luck. And I tried all the usual things: delete app, clear cache, reboot, reinstall app, no luck.

The only thing that worked for me, was to rename the virtual directory on my web server. This might not be a viable solution for everyone, but luckily for, this was not really a problem, as I'm testing using a local IIS server.

爱人如己 2024-12-25 16:46:46

要解决此问题,您应该在链接末尾添加新的字母和数字(不仅仅是数字),如下所示:

?v1
?x2
?z3

每次您想要更新脚本时,您应该添加不同的字母和数字(需要不同的字母,因为如今许多移动浏览器忽略 Javascript/CSS 链接末尾的所有纯数字。)

To fix this problem you should add new letters with numbers (not just numbers) to the end of link like that:

?v1
?x2
?z3

And every time you want to update your script, you should add a different letters and numbers (different letters is required because today many mobile browsers are ignoring all pure numbers in the end of Javascript/CSS link.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文