简体   繁体   English

(如何)我可以指示Chrome / Firefox / IE /…不要缓存特定网站?

[英](How) can I instruct Chrome/Firefox/IE/… not to cache a specific website?

I have built a browser extension that, on startup, calls a web service from which it retrieves a JSON result. 我建立了一个浏览器扩展程序,该扩展程序在启动时会调用Web服务,并从中检索JSON结果。 The JSON result contains data that will be shown in the popup of the extension. JSON结果包含将在扩展的弹出窗口中显示的数据。 This data is updated at least once a day using a prepared, scheduled update service. 使用准备好的预定更新服务,每天至少更新一次此数据。 Furthermore, the data is irregularly manually updated intra-day. 此外,数据会在一天中不定期手动更新。

The data that is retrieved from the web service does not automatically adapt to the changes that are made. 从Web服务检索的数据不会自动适应所做的更改。 Particularly, the extension retrieves old results from the web service. 特别是,扩展名从Web服务检索旧结果。 The web service is tested and always returns the newest result, hence this is not a server-side problem (at least not with regards to the computation, storage and provision of the data). 该Web服务已经过测试,并且始终返回最新结果,因此,这不是服务器端的问题(至少与数据的计算,存储和提供无关)。

I noticed that sometimes the web service appears to return old results, which then after a page refresh are updated. 我注意到有时Web服务似乎返回旧结果,然后在刷新页面后更新这些结果。 I believe this happens due to some caching mechanism(s) client- or server-side. 我相信这是由于某些客户端或服务器端缓存机制引起的。

Researching the topic has not yielded any helpful resource or material 研究主题尚未产生任何有用的资源或材料

Is it possible for me to instruct the extension to not cache results from the web service and/or instruct the server to not allow/serve cached results? 我是否可以指示扩展程序不缓存来自Web服务的结果和/或指示服务器不允许/保留缓存的结果?

Any advice and/or resource regarding this issue is very much appreciated. 非常感谢有关此问题的任何建议和/或资源。

One usual way would be to add a random extension to your HTTP GET path - a parameter, not used by the server. 一种常用的方法是向您的HTTP GET路径添加一个随机扩展名-一个参数,服务器不使用。 By doing this, the browser cannot use cached data, because it just has not got any for this URL. 这样,浏览器将无法使用缓存的数据,因为它没有该URL的任何数据。 The server will simply ignore the additional parameter. 服务器将简单地忽略附加参数。

Here is an example, please change the value of the random parameter (12345 in this example) with each call to the server. 这是一个示例,请在每次调用服务器时更改random参数的值(此示例中为12345)。

// Original URLs
http://www.example.com/myservice
http://www.example.com/myservice?param=data

// With an Additional HTTP Parameter
http://www.example.com/myservice?random=12345
http://www.example.com/myservice?param=data&random=12345

If you have control over server software right thing to do is to configure it to set proper caching related HTTP header values. 如果您可以控制服务器软件,则可以将其配置为设置适当的缓存相关HTTP标头值。 To prevent caching you need to set Cache-Control header value and Expires header value. 为了防止缓存,您需要设置Cache-Control标头值和Expires标头值。 Check this thread for a cross-browser solution. 检查此线程以获取跨浏览器解决方案。 In order to not transfer to the clients data that is not stale yet again and again use either ETag or Last-Modified header values. 为了不再次将尚未过时的数据传输到客户端,请再次使用ETagLast-Modified标头值。 For more information about ETag , conditional requests and HTTP caching in general check HTTP caching tutorial and HTTP protocol specification . 有关ETag ,条件请求和HTTP缓存的详细信息,请参阅HTTP缓存教程HTTP协议规范

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在所有浏览器(IE,Chrome和Firefox)中获得相同的innertext ptoperty值 - How can I get same innertext ptoperty value in all browsers (IE, Chrome and Firefox) 我的输入字段在IE上以内联方式呈现,但在Chrome和Firefox中以换行方式呈现。 我该如何解决? - My input fields render inline on IE, but on new lines in Chrome and Firefox. How can I fix that? 如何在Chrome,Firefox和IE中显示MJPEG,H264 Live Stream和播放视频? - How can I show MJPEG, H264 Live Stream, and playback video in Chrome, Firefox and IE? 如何获取Firefox / IE / Chrome中可见标签的URL? - How do I get the URL of the visible tab in Firefox/IE/Chrome? 如何在HTML页面或SCSS文件中具体说明Chrome和IE的css规则? - How can I to specific the css rules for Chrome and IE in my HTML page or in SCSS file? 为什么我不能在IE 9中进行递归$ http请求,但在Firefox和Chrome中却可以 - Why Can't I make recursive $http requests in IE 9 but I can in Firefox and Chrome Firefox和IE图像缓存 - Firefox and IE image cache 如何将Google表单嵌入与IE,Chrome和Firefox兼容的网页中? - How do I embed a google form into a webpage compatible with IE, Chrome, and Firefox? 如何css html在IE中显示图像,可以在Firefox,Chrome和Safari中查看? - How to css html to display image in IE, which can be viewed in firefox, chrome, and safari? 如何解决Firefox中的跨度/格问题(在IE中按需显示)以及如何调整Chrome中的未对准? - How do I fix span/div issues in Firefox (displays as wanted in IE) and adjust misalignment in Chrome?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM