jQuery 为什么我的 Mobile Safari 缓存无法清除?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11754305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 10:54:22  来源:igfitidea点击:

Why my Mobile Safari cache won't clear?

jqueryiphonecachingjquery-mobilerequirejs

提问by frequent

I'm trying to debug a site on my iPhone4 (iOS4) iPad1 (iOS3.3) and desktop.

我正在尝试在我的 iPhone4 (iOS4) iPad1 (iOS3.3) 和桌面上调试网站。

My problem is I cannot clear the iPhone cache at all.

我的问题是我根本无法清除 iPhone 缓存。

If I add alerts/consoles to the js files I'm debugging, they show up on iPad and desktop, but the iPhone just keeps reloading from the cache.

如果我向正在调试的 js 文件添加警报/控制台,它们会显示在 iPad 和桌面上,但 iPhone 只是不断从缓存中重新加载。

If I clear the cache through settings>safari>delete browser history, cache, cookiesand in Safari delete all bookmarks and remove the files on the server, iPad and desktop break (missing files) but the iPhone still loads the page as if nothing happened.

如果我通过settings>safari>delete browser history, cache, cookiesSafari清除缓存并在 Safari 中删除所有书签并删除服务器、iPad 和桌面中断(丢失文件)上的文件,但 iPhone 仍然加载页面,好像什么也没发生。

Not sure this is the right place to ask, but maybe someone else has a similar experience and an idea how to workaround?

不确定这是问的正确地方,但也许其他人有类似的经验和想法如何解决?

Thanks!

谢谢!

EDIT:
I played around with this some more. If I start an appliction through the icon the cache seems cleared. Only when I open the page in Mobile Safari, it still uses the wrong file from cache. Pointers still welcome!

编辑
我又玩了一些。如果我通过图标启动应用程序,缓存似乎已清除。只有当我在 Mobile Safari 中打开页面时,它仍然使用缓存中的错误文件。仍然欢迎指点!

EDIT:
I'm starting a bounty on this. I'm using RequireJS and JqueryMobile on the site, so these may also be reasons for the cache not clearing. Still, I don't understand why it clears in app-mode and why it doesn't clear in Mobile Safari.

编辑
我正在为此悬赏。我在网站上使用 RequireJS 和 JqueryMobile,所以这些也可能是缓存未清除的原因。不过,我不明白为什么它在应用程序模式下清除,为什么在 Mobile Safari 中不清除。

I have tried the following:
1. Clicking reload pagein the URL bar does not clear the cache. Clicking on the link and then loading the page via godoes seem to clear the cache once in a while

我尝试了以下方法:
1.reload page在 URL 栏中单击不会清除缓存。单击链接然后通过加载页面go似乎偶尔会清除缓存

采纳答案by joevallender

Even though this is a bit hacky, maybe have a go at this workaround (I'm assuming this is for development)

尽管这有点hacky,但也许可以尝试一下这个解决方法(我假设这是为了开发)

As per the notes in disabling ajax cacheing here How to disable Ajax caching in Safari browser?you could set no-cache headers while developing or in plain HTML like this

根据此处禁用 ajax 缓存中的说明如何在 Safari 浏览器中禁用 Ajax 缓存?您可以在开发时或像这样在纯 HTML 中设置无缓存标头

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

obviously it won't fix your initial issue of being stuck. but you can break the cycle by adding an arbitrary query parameter ?something=3164 so the URL is effectively unique. then next time it loads hopefully it will hold onto the no-cache params.

显然它不会解决你最初被卡住的问题。但是您可以通过添加任意查询参数 ?something=3164 来打破循环,因此 URL 实际上是唯一的。然后下次加载时它会保留无缓存参数。

If even that then doesnt work you could set up a bookmark which redirected you to a different random=14361 number each time to they are all effectively unique calls - but then we're getting into silly territory!

如果即使那样也不起作用,您可以设置一个书签,每次将您重定向到不同的 random=14361 号码,因为它们都是有效的唯一调用 - 但是我们进入了愚蠢的领域!

I'd like to have a proper solution but when I'm developing JS webapps I've found that sometimes everything refreshes properly for a while, then sometimes it doesnt... no real pattern i can tell - apart from the fact i think it seems to do it less when the debugger is enabled (but thats totally unsubstantiated ;-)

我想有一个适当的解决方案,但是当我开发 JS webapps 时,我发现有时一切都会正常刷新一段时间,然后有时它不会......我无法分辨出真正的模式 - 除了我认为的事实启用调试器时,它似乎做得更少(但这完全没有根据;-)

回答by ilo

When developing for iOS mobile, you can clear the cache easily by plugging the phone to a computer via USB and using the developing tools:

为iOS手机开发时,可以通过USB将手机插入电脑,使用开发工具轻松清除缓存:

  1. In the phone, enable developing tools: Settings/Safari/Advanced
  2. In the computer, enable Safari develop menu: Settings/Advanced
  3. Make sure the mobile Safari is open and inspect the phone: Develop/PHONE_NAME/TAB_NAME
  4. Now you press cmd-shift-r to clear the cache in phone
  1. 在手机中开启开发工具:设置/Safari/高级
  2. 在电脑中,启用Safari开发菜单:设置/高级
  3. 确保移动版 Safari 已打开并检查手机:Develop/PHONE_NAME/TAB_NAME
  4. 现在您按 cmd-shift-r 清除手机中的缓存

回答by MidnightLightning

Are you dealing with an HTML5 "offline" application? The use of a manifest file for offline apps is quite new, and has strange quirks for each browser. Modify the manifest file on the server, and the iPhone should fetch the pages again.

您是否正在处理HTML5“离线”应用程序?离线应用程序清单文件的使用是相当新的,并且每个浏览器都有奇怪的怪癖。修改服务器上的清单文件,iPhone 应该再次获取页面。

EDIT: If you ever had a manifest file (and the HTML attribute pointing to it), if you remove the manifest in the wrong order, your cache can get tangled:

编辑:如果您曾经有一个清单文件(以及指向它的 HTML 属性),如果您以错误的顺序删除清单,您的缓存可能会变得混乱:

  1. HTML and manifest exist
  2. Remove the manifest file, and reload the HTML page => HTML page shouldun-manifest, since manifest 404's, but on some browsers it doesn't.
  3. Modify the HTML => HTML page doesn't un-cache, since the (non-existant) manifest file hasn't changed.
  1. HTML 和清单存在
  2. 删除清单文件,并重新加载 HTML 页面 => HTML 页面应该取消清单,因为清单 404,但在某些浏览器上没有。
  3. 修改 HTML => HTML 页面不会取消缓存,因为(不存在的)清单文件没有改变。

To correctly un-manifest it, try:

要正确取消显示它,请尝试:

  1. Add the HTML and manifest back in
  2. Remove the HTML manifest attribute first, and reload the page
  3. Then remove the manifest file from the server.
  1. 重新添加 HTML 和清单
  2. 首先移除 HTML manifest 属性,然后重新加载页面
  3. 然后从服务器中删除清单文件。

回答by Jigar Pandya

Try stopping safari and restart it and delete all the pages that are there in safari.... see the image how to close the pages enter image description here

尝试停止 safari 并重新启动它并删除 safari 中存在的所有页面.... 查看图像如何关闭页面 在此处输入图片说明

回答by Ankur Ghelani

there is another solution with out restarting your device for safari,

还有另一种解决方案,无需为 Safari 重新启动设备,

  1. Go to Settings
  2. Then go down and go to Safari
  3. Then go down and see options Clear Cookie and Dataas in below ImageiPhone Safari Clear Cookie and Data

  4. Now go back to your safari and you are done!

  1. Settings
  2. 然后下去去 Safari
  3. 然后往下看Clear Cookie and Data,如下图所示iPhone Safari 清除 Cookie 和数据

  4. 现在回到你的野生动物园,你就完成了!

if you have any more question comment below.

如果您有更多问题请在下方评论。