如何创建“清除缓存”我的网站的按钮?

发布于 2024-11-17 10:00:55 字数 64 浏览 8 评论 0原文

我想在我的网站上创建一个按钮来完全清除我的缓存。 Safari 和 Chrome 的功能似乎都不起作用。这可能吗?

I'd like to create a button on my site that COMPLETELY clears my cache. As neither Safari's nor Chrome's features work at all it seems. Is this possible?

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

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

发布评论

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

评论(3

泪眸﹌ 2024-11-24 10:00:55

不可能。这会将低级功能公开给公众访问。即使漏洞利用只是清空你的缓存,它仍然是不可取的。 Firefox 和 Chrome 都使用 shift-ctrl-del 来实现此目的,因此您可以在不存在安全风险的情况下执行相同的操作,但实际上必须使用键盘。

Not possible. That'd expose low-level functionality to public access. Even if an exploit would simply empty your cache, it'd still be undesireable. Firefox and Chrome both use shift-ctrl-del for this, so at the cost of actually having to use your keyboard, you can do the same thing without the security risk.

樱花落人离去 2024-11-24 10:00:55

听起来您想要清除服务器和浏览器之间的缓存数据,而不是浏览器缓存的数据。您的资源副本可能位于客户端计算机和服务器之间的计算机上,这会返回缓存的副本,而不是再次向服务器请求数据。

您应该阅读不同的缓存方法,以便您可以将某些类型的文件设置为缓存一定时间等。尝试 这个 对于初学者来说。


我通常将静态资源(css、js等)设置为缓存很长一段时间,但是当我对其进行更改时,我会更改URL。我通常通过重写请求 url 来实现此目的,使 /resources/dummy/file.css 变为 /resources/file.css 并且我可以更改 dummy 每当我想要的时候。这会创建一个不同文件(尚未缓存)的暗示,但我不必重命名该文件。

RewriteRule  resources/[^/]+/([^/]+)$  resources/$1

It sounds like you want to clear the cached data that sits between your server and your browser, not the data that the browser has cached. A copy of your resources mat be sitting on a machine between your client computer and your server, and that is returning the cached copy, instead of asking your server for the data again.

You should read up on different caching methods, so you can set up certain types of files to be cached for a certain amount of time etc. Try this for starters.


I usually set up static resources (css, js, etc.) to be cached for a long period of time, but I change the URL when I have made changes to it. I usually do this by rewriting the request url so /resources/dummy/file.css becomes /resources/file.css and I can change dummy whenever I want. This creates the allusion of a different file (that hasn't been cached yet) but I don't have to rename the file.

RewriteRule  resources/[^/]+/([^/]+)$  resources/$1
何必那么矫情 2024-11-24 10:00:55

高度怀疑这是否可能,而且您希望它是跨浏览器的。它将产生严重的安全漏洞以供利用。

Highly doubt this is possible moreover you want it to be cross-browser. It will create serious security flaw to be exploit.

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