如何在reactjs中清除浏览器缓存 [英] how to clear browser cache in reactjs

查看:2590
本文介绍了如何在reactjs中清除浏览器缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我对网站进行更改并尝试将这些更改更新为正在运行的网站时,我都必须刷新浏览器.有什么办法可以通过代码做到这一点

every time I make changes to my website and try to update those changes to the running website, I've to hard refresh browser. is there any way to do it by code

我已经尝试搜索它,但是大多数都说它无法完成. 参考文章:如何以编程方式清空浏览器缓存?

i already try to search it but most of saying it can not be done. referance post : How to programmatically empty browser cache?

**响应标头:

HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Fri, 06 Jul 2018 10:01:23 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Content-Encoding: gzip

**请求标头:

GET / HTTP/1.1
Host: --example--.com
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8,hi;q=0.7
Cookie: fingerPrint=e4a9037b8f674722f414b0b59d8d663c

推荐答案

对于这种特定情况,您可以通过在<head>标记内使用这些元标记来告诉浏览器不要缓存您的页面:

For this specific case what you can do is to tell browser not to cache your page, by using these meta tags inside <head> tag:

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

但是,有多种方法可以实现这一目标.您可以从后端发送适当的标头.或者,如果您尝试暂时禁用缓存,则可以通过禁用浏览器缓存来实现.为此,请按照以下步骤操作.

However there are multiple ways to achieve this. You could send the appropriate headers from your back end. Or if you are trying to disable cache temporally you can do it by disabling the browser cache. To do so, Follow below steps.

在您的开发人员工具中.查找网络选项卡并禁用缓存.就像图片中的这里一样.

In your developer tools. Find network tab and disable cache. Like here in the image.

希望这能解决.

这篇关于如何在reactjs中清除浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆