在 jquery-stream 插件上实现 If-Modified-Since 客户端缓存

发布于 2024-12-21 08:56:31 字数 321 浏览 4 评论 0原文

我有一个用例,需要从服务器传输 JSON,现在我正在考虑缓存响应。与 JQuery 的 .ajax 函数不同,jquery-stream 提供的 .stream 函数似乎不支持 IfModified HTTP 标头。我已设法更改源以设置 If-Modified-Since 标头,但我不确定如何访问客户端缓存以使用缓存的响应而不是服务器响应。目前,jquery-stream 检测到 304(未修改),然后关闭流,将 xhr 对象上的responseText 留空。有没有办法手动访问客户端缓存,也许可以使用 data() 函数?

如果我找到答案,我将尝试实现它并将更改提交到 jquery-stream 项目。

I've got a use case that requires streaming JSON from a server, and now I'm looking at caching the responses. Unlike JQuery's .ajax function, the .stream function provided by jquery-stream doesn't seem to have support for the IfModified HTTP header. I've managed to alter the source to set the If-Modified-Since header, but I'm not sure how to access the client-side cache to use the cached response instead of the server response. Currently, jquery-stream detects the 304 (Not Modified) and then closes the stream, leaving the responseText on the xhr object blank. Is there a way to manually access the client-side cache, perhaps with the data() function?

If I find out the answer I'll have a go at implementing it and submit the changes to the jquery-stream project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪失控 2024-12-28 08:56:31

首先,我想知道为什么您担心长期保留请求的客户端缓存。我通过附加时间戳参数强制浏览器不缓存流请求。 prepareURL 函数 可以做到这一点。

由于 iframe 和 xdr 传输无法发送请求标头,因此即使您的实现与 xhr 传输一起使用,也无法普遍应用。很遗憾。

谢谢你的意见。

——东焕

First of all, I'm wondering why you are concerend about client-side caching of long-held request. I forced a stream request not to be cached by the browser by appending a timestamp parameter. prepareURL function does it.

Because iframe and xdr transport cannot send request header, your implementation cannot be applied in general even though it works with xhr transport. Unfortunately.

Thanks for your opinion.

-- Donghwan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文