防止在从磁盘加载的 UIWebView 中缓存 .css 文件 [英] Prevent caching of .css files in UIWebView loaded from disk

查看:13
本文介绍了防止在从磁盘加载的 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆