绕过缓存的 HTML 链接? [英] HTML link that bypasses cache?

查看:20
本文介绍了绕过缓存的 HTML 链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从我的网站链接到的文件,例如

I have a file that I link to from my website like

<a href="http://example.com/myfile.txt>View!</a>

但是,此文件更改非常频繁,单击链接时,浏览器会加载文件的缓存版本,而不是实际文件.有没有办法让点击那个链接绕过那个页面的缓存?

However, this file changes very frequently and when the link is clicked, the browser loads the cached version of the file, not the actual file. Is there a way so that clicking on that link will bypass the cache for that page?

<a bypassCache href=""> 这样的好东西将是一厢情愿的想法.

Something nice like <a bypassCache href=""> would be wishful thinking.

推荐答案

美好的事物就像是一厢情愿.

Something nice like would be wishful thinking.

确实,您可以从链接中执行一些操作:添加随机 GET 参数.

Indeed, there is something you can do from within the link: Add a random GET parameter.

<a href="http://example.com/myfile.txt?a=193834923283943842923">View!</a>

您可以使用 JavaScript(当然也可以使用 PHP 等服务器端脚本语言)来动态执行此操作.

You could use JavaScript (or of course a server-side scripting language like PHP) to do this on a dynamic basis.

然而,更好的方法是首先在服务器端正确配置文本文件的缓存头.从禁用客户端缓存的最佳方法(.htaccess 文件)中窃取标头信息像这样应该可以工作:

However, the far superior way would be to configure the text file's caching headers correctly in the first place on server side. Stealing the header info from Best way to disable client caching, a .htaccess file like this should work:

<Files myfile.txt>
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header set Cache-Control "store, no-cache, must-revalidate, post-check=0, pre-check=0"
Header set Pragma "no-cache"
Header set Expires "Sun, 19 Nov 1978 05:00:00 GMT"
</IfModule>
</FilesMatch>

这篇关于绕过缓存的 HTML 链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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