简体   繁体   English

如何在主屏幕上清除IOS Web App的缓存?

[英]How can I clear the cache of an IOS Web App on the Homescreen?

I am using JQTouch to create a Web App on the Homescreen using meta tag "apple-mobile-web-app-capable", but no matter how many times I clear the cache from within Settings, the Web App's Javascript is still an older cached version. 我正在使用JQTouch在主屏幕上使用元标记“apple-mobile-web-app-capable”创建Web应用程序,但无论我在设置中清除缓存多少次,Web App的Javascript仍然是较旧的缓存版。

Strangely enough, if I set the meta tag's content to; 奇怪的是,如果我将元标记的内容设置为;

<meta name="apple-mobile-web-app-capable" content="no" />

...then add the Web App to the Homescreen, I get the latest version when I launch it. ...然后将Web App添加到主屏幕,我在启动时获得最新版本。

Yet if I set the meta tag to; 然而,如果我将元标记设置为;

<meta name="apple-mobile-web-app-capable" content="yes" />

...then add the Web App to the Homescreen, I get the older cached version. ...然后将Web App添加到主屏幕,我得到较旧的缓存版本。

PS. PS。 I can confirm that is only the javascript which will not refresh. 我可以确认只有不会刷新的javascript

You could try adding a unique string to the end of your js include's src attribute (use a timestamp, for example). 您可以尝试在js include的src属性的末尾添加一个唯一的字符串(例如,使用时间戳)。 Bear in mind you'll have to change this unique string for each refresh you want to do, so you may want to consider doing lazy-loading (which may in itself solve your problem): <script type="text/javascript" src="myScript.js?012345"></script> 请记住,您必须为每个要执行的刷新更改此唯一字符串,因此您可能需要考虑进行延迟加载(这本身可以解决您的问题): <script type="text/javascript" src="myScript.js?012345"></script>

This usually forces the browser into grabbing the latest version of the script. 这通常会迫使浏览器抓取最新版本的脚本。 Might work... 可能会工作......

This is a way that worked for me to clear completely the cache: 这是一种让我彻底清除缓存的方法:

1-Delete the tabs in safari where there is your app. 1 - 删除有应用程序的safari中的选项卡。
2-Delete the icon of the app in the home screen. 2 - 在主屏幕中删除应用程序的图标。
3- Kill safari from the memory. 3-从记忆中杀死野生动物园。
4-Go to settings/safari and press clear cache. 4 - 进入设置/旅行,然后按清除缓存。
5-You can restart your iPhone/iPod if you want to be sure that it works 5 - 如果要确保它可以正常工作,可以重新启动iPhone / iPod

I found that using bundling feature in ASP.NET MVC solved this problem for me. 我发现在ASP.NET MVC中使用捆绑功能为我解决了这个问题。

It automatically generates a bundled link of the form: 它会自动生成以下形式的捆绑链接:

http://www.domain.com/MvcBM_time/bundles/AllMyScripts?v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81 http://www.domain.com/MvcBM_time/bundles/AllMyScripts?v=r0sLDicvP58AIXN_mc3QdyVvVj5euZNzdsa2N1PKvb81

The token after the v= changes if any file in the bundle changes, guaranteeing that browser requests for the bundle will get the latest bundle. 如果包中的任何文件发生更改,则v =更改后的标记会发生更改,从而保证对该包的浏览器请求将获得最新的包。

如果你越狱了,就在终点站这样做吧

rm ./Library/Caches/com.apple.webapp/Cache.db

This drove me absolutely nuts. 这让我绝对疯了。 I tried killing Safari, clearing the cache, switching to private mode, and removing the web app from the home screen. 我尝试杀死Safari,清除缓存,切换到私人模式,并从主屏幕中删除Web应用程序。 None of those work, but what does work is temporarily loading the web app page in Safari itself and reloading . 这些都不起作用,但是在Safari本身临时加载Web应用程序页面并重新加载的工作是什么。

If you're using add to home screen , you can add ?web_app_ready=1 to the install URL. 如果您使用添加到主屏幕 ,则可以将?web_app_ready = 1添加到安装URL。 Since that's not an end user procedure, adding a query string to every script (the answer above) will probably be more effective for non-developer environments. 由于这不是最终用户程序,因此向每个脚本添加查询字符串(上面的答案)对于非开发人员环境可能更有效。

Building off of what SquareFeet said, one could automatically pull the new file down every time with a unique GET tag appended to the filename, using PHP. 建立在SquareFeet所说的基础上,每次都可以使用PHP在文件名后附加一个唯一的GET标记,自动将新文件拉下来。 For example: 例如:

<link rel="stylesheet" type="text/css" href="/css/global.css?
   <?php echo(mt_rand(10000000, 99999999)); ?>
" />

Theoretically, the same task could be accomplished using JavaScript, albeit with some modifications to the web server: 从理论上讲,使用JavaScript可以完成相同的任务,尽管对Web服务器进行了一些修改:

<link rel="stylesheet" type="text/css" href="/css/global.css?
   <div id="id"></div>
" />

<script language="Javascript" type="text/javascript">
   document.getElementById("id").innerHTML = Math.floor((Math.random() * 10000) + 1);
</script>

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

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