图像缓存在浏览器中后,通过请求图像来检查互联网连接不起作用
当图像缓存在浏览器中后,通过请求图像来检查互联网连接将不起作用。一两次后,这不起作用,因为图像存储在浏览器的缓存中,那么有什么解决方案吗?或者我需要什么来检查连接是否可用? window.navigator.online
不可靠。所以寻找其他有趣且可靠的解决方案。
Checking of internet connection by requesting an image does not work after the image gets cached in the browser. After one or two time, this doesn't work as the image is stored in the browser's cache so is there any solution for that? Or what do I need to check whether a connection is available or not? window.navigator.online
is not reliable. so looking for the other interesting and reliable solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用缓存破坏器查询字符串。查询字符串强制浏览器检查新图像的服务器。
Use a cache buster querystring. The querystring forces the browser to check the servver for the new image.
使用 XMLHttpRequest 对象和 POST 协议。 POST 请求不会被缓存。但这仅适用于从与页面相同的域加载图像(或任何其他资源)(XMLHttpRequest 限制)。
Using XMLHttpRequest object and POST protocol. POST-request does not cached. But this works only if image (or any other resource) loaded from the same domain as page (XMLHttpRequest limitation).
检查互联网连接的完美解决方案是对虚拟页面的服务器进行 ajax 调用,并将该虚拟页面的条目放入网络部分的应用程序缓存清单文件中,以便它不会在浏览器中缓存,否则它会丢失从浏览器中获取该文件,即使您处于离线模式,也会显示您在线。
The perfect solution for checking internet connectivity is to give a ajax call to your server to the dummy page and make that dummy page's entry in the application cache manifest file in the network section so that it may not get cached in the browser, otherwise it wl take that file from browser and show you as online even if u are in offline mode.