在从磁盘加载的UIWebView中阻止缓存.css文件 [英] Prevent caching of .css files in UIWebView loaded from disk
问题描述
在iPad项目中,我在工作中有一个 UIWebView
里面的应用程序显示一个.html文件,链接到一个.css文件,即
In the iPad project I'm working on I've got a UIWebView
inside of the app which displays a .html file which links to a .css file, i.e.
<link rel="stylesheet" href="style.css" type="text/css">
这些文件存储在iPad本地,但从远程服务器获取。我注意到 UIWebView
缓存.css文件或多或少无限期,并拒绝加载新文件,每当我改变它。我已经改变了文件的名称,只是为了让它重置,但这是不可接受的长期。
These files are stored locally on the iPad but are fetched from a remote server. I've noticed that UIWebView
caches the .css file more or less indefinitely, and refuses to load the new file whenever I change it. I've once changed the name of the file just to get it to reset, but that's unacceptable in the long run.
有一种方法来防止缓存的CSS文件在 UIWebView
?
Is there a way to prevent caching of the CSS file in a UIWebView
? Or even better, is there a way to say when to cache and when not to?
推荐答案
是的。
将您的行更改为:
<link rel="stylesheet" href="style.css?version=1" type="text/css">
每次更新样式表时,请更改版本。浏览器会认为它是一个不同的页面,因为查询字符串,您的服务器将忽略它。
Every time that you update the stylesheet, change the version. The browser will think that it is a different page because of the query string, and your server will ignore it.
如果您使用服务器端语言如PHP,您还可以执行以下操作:
If you are using a server side language such as PHP, you can also do the following:
<link rel="stylesheet" href="style.css?version=<?php echo time(); ?>" type="text/css">
这将在每次刷新时更改版本,从而停止所有缓存。
This will change the version every time you refresh, thus stopping all caching.
这篇关于在从磁盘加载的UIWebView中阻止缓存.css文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!