强制刷新 CSS 文件 [英] Force refresh of CSS files

查看:74
本文介绍了强制刷新 CSS 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WebView,它从我的应用程序的私有数据中加载 HTML 文件.我从服务器加载这些文件,然后将它们保存到私有数据文件夹中.它们带有 JavaScript 文件、CSS 文件、图像等.所以我的 WebView 然后可以很好地显示这些 HTML 文件.

I have a WebView that loads HTML files from within the private data of my app. I load those files from a server, then saves them to the private data folder. They come with JavaScript files, and CSS files, images, etc. So my WebView then display those HTML files just fine.

我的问题是当我在我的服务器上修改这些文件的内容,然后在应用程序中再次下载这些文件(首先我确保所有文件都从私有数据文件夹中删除)并打开 WebView,除了 CSS 文件之外的所有内容都更新了,样式保持不变.我发现在 WebView 中强制更新 CSS 文件的最快解决方案是删除应用程序的所有内容(在设置中),然后再次下载文件.

My problem is when I modify the content of those files on my server, and then download those files again in the app (first I made sure all files were deleted from the private data folder) and open the WebView, everything is updated except for the CSS files, the style remains the same. The quickest solution that I found to force the CSS files to be updated in the WebView is to delete all content for the app (in the settings) and then download the files again.

注意:由于我在 WebView 上使用本地存储,所以我不想清除所有数据(如历史记录或其他任何数据),但如果可能,清除资源很好.

Note: I don't want to clear all data like history or whatever since I am using local storage on the WebView, but clearing resources is fine, if possible.

推荐答案

如果可能,在调用 css 文件名时添加时间戳或唯一值.我在我的 webapp 中使用这个方法虽然我使用 php 附加时间戳,但我确定它可以在 html 中使用 JS 完成,也可以使用 event.timeStamp.

Add a timestamp or unique value to the end of the css filename when calling it if possible. I use this method within my webapp although i append the timestamp using php, im sure it can be done in html with JS also using event.timeStamp.

例如

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.0-alpha.2/jquery.mobile-1.4.0-alpha.2.min.css?timestamp=<? echo $timestamp?>">

希望这会有所帮助.

这篇关于强制刷新 CSS 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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