HTML5 appcache,获取客户端中缓存文件的列表
在我的项目中,我尝试使用 HTML5 appcache 来缓存 CSS 和 JS 等静态资源,以及图像和视频等“用户特定”文件。当我说用户特定的图像/视频时,我试图为每个用户提供单独的文件,并且我还需要控制文件下载的顺序。
在这种情况下,我的清单文件将为每个用户动态加载。有没有办法获取已缓存在客户端的资源列表?
如果没有,是否可以读取客户端中的“.appcache”文件?
In my project, I'm trying to use HTML5 appcache to cache static resources like CSS and JS, and "user specific" files such as images and videos. When I say user specific images/videos, I'm trying to have separate files for each user and I need to control order of the file download as well.
Given the scenario, my manifest file will be dynamically loaded for every user. Is there a way where I can get a list of resources that are already cached in client side?
If not, is is possible to read the ".appcache" file in client?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。您可以使用AJAX请求来获取清单缓存文件,然后读取它。
但是,这并不能保证问题中的浏览器具有可用的文件。
下面是一个示例代码
检查我们是否缓存了 HTML5 应用程序
如果我们没有处于缓存状态,则计算清单中加载的资源并根据清单缓存条目计数(总计)显示进度条,并对所有 URL 执行手动 AJAX GET 请求以预热缓存。浏览器会自己执行此操作,但这样我们可以从进程中获取一些进度信息。
当缓存处于已知的良好状态时,继续前进
免责声明:自 2010 年以来未进行过测试
Yes. You can use AJAX request to get the manifest cache file and then read it.
However, this does not guarantee that the browser in the question has the files available.
Below is an sample code
Which checks if we have cached HTML5 app or not
If we are not in a cached state then count loaded resources in the manifest and display a progress bar according to the manifest cache entry count (total) and do a manual AJAX GET request for all URLs to warm up the cache. The browser will do this itself, but this way we can get some progress information out of the process.
When cache is in a known good state, move forward
Disclaimer: not tested to work since 2010
我还一直在研究一种解决方案来发现正在缓存的文件,并提出了以下方案。
.htaccess 包装器,用于将文件抓取到应用程序缓存的目录。
然后我的 auth.php 文件将文件(以块的形式)返回到浏览器,但同时也使用之前声明的 APPID 记录到服务器(我使用数据库表)。
这样,当检测到“进度”事件时,可以进行 AJAX 调用来检索 APPID 的最后一个条目,其中包含文件名和已发送的数据量。
使用此方法的优点是它对于访问“.htaccesswrapped”文件夹中的文件的其他方法是透明的,并且在我的例子中还包括身份验证。
当由于某种原因未被授权访问文件时,我返回“未授权”标头。
I have also been working on a solution for discovering which file is being cached, and have come up with the following.
.htaccess wrapper for the directory we are grabbing files to appcache.
then my auth.php file returns the file (in chunks) to the browser, but also logs at the same time to the server (I use a DB table) with an earlier declared APPID.
That way while the 'progress' event is detected, an AJAX call can be made to retrieve the last entry for APPID, which contains the file name and how much data has been sent.
The advantage of using this method is that its transparent to other methods accessing the files in the '.htaccess wrapped' folder, and in my case also includes authentication.
When not authorized to access a file for whatever reason I return 'Not Authorized' headers.