Prevent caching of .css files in UIWebView loaded from disk(防止在从磁盘加载的 UIWebView 中缓存 .css 文件)
问题描述
在我正在处理的 iPad 项目中,我在应用程序内部有一个 UIWebView
,它显示了一个链接到 .css 文件的 .html 文件,即
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.
有没有办法防止在 UIWebView
中缓存 CSS 文件?或者更好的是,有没有办法说明什么时候缓存什么时候不缓存?
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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:防止在从磁盘加载的 UIWebView 中缓存 .css 文件


- UITextView 内容插图 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- URL编码Swift iOS 2022-01-01