I have a mobile website, wherein i have a page which can be used for offline viewing, i am aware of the manifest
, and added required resources in it.
Now i also want to cache data which is getting pulled from database, for which i have a web API
, which pulls in content from database, and i am calling that web API
in my web application using jQuery
.
Below is the code i have tried:
CACHE MANIFEST
#version 1
css/styles.css
js/script.js
js/libs/jquery-1.5.2.min.js
js/libs/underscore-min.js
Can anyone take me to the right path to do this.
答案 0 :(得分:1)
还有另一种方法。
假设您的api请求具有以/api/*/*
开头的URL,您可以将此路径的客户端缓存设置为非常长的持续时间。因此,当您离线时,您的应用程序将从浏览器缓存中选择数据。对于联机模式,您必须将缓存破坏程序附加到URL。例如/api/*/*?<timestamp>
。这样可以减少在保存到服务器时数据发生变化时必须实现保存到/读取localStorage并更新localStorage值的逻辑量。
答案 1 :(得分:0)
是的,确实,本地存储仅适用于少量数据。
您可以尝试IndexedDB API。 但是,请留意browser support。
有一些垫片针对较旧的浏览器,例如this one。它默认为WebSQL,几乎是well supported。值得注意的是,WebSQL已被弃用。