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 文件


基础教程推荐
- 如何使 UINavigationBar 背景透明? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 固定小数的Android Money Input 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01