go - Gin静态文件缓存

标签 go

是否可以在 Gin (golang) 中缓存静态文件?

我试过:

router := gin.Default()
router.Static("/assets", "./assets") 

但是每当我刷新页面时,我都会收到状态代码为 200 的响应。我认为它应该是 304(或类似的),但是 https://github.com/gin-gonic/gin没有提到 HTTP 缓存(至少现在是这样)。

如何在 gin 中处理静态文件缓存?

最佳答案

如果您使用的是 Chrome,这可能是原因:

You probably have the Disable cache (while DevTools is open) option selected in the Preferences panel of DevTools. Chrome is sending Cache-control:no-cache header

enter image description here

关于go - Gin静态文件缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49724142/

相关文章:

go - 如何在 Go 中从 netcat 打印 TCP 消息?

email - 使用 Go/TLS 发送电子邮件会产生 "remote error: handshake failure"响应

pointers - 我如何在 Go 中做一个文字 *int64?

docker - 使用 Dockerfile 时找不到二进制文件

google-app-engine - Google App Engine 下载数据验证错误

go - 如何解决直径连接错误:使用封闭的网络连接?

mongodb - 如何构建bson.D {}

nginx - Go:在模板中的 if 语句中使用环境变量

go - 具有多个映射符号的结构

go - GetById 和 CreateOrUpdate 不起作用