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

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

问题描述

我有链接到我的网站就像搜索

文件

 &LT; A HREF =htt​​p://example.com/myfile.txt>View!</a>

但是,此文件的变化非常频繁,并单击链接时,浏览器加载文件的缓存版本,而不是实际的文件。
有没有办法让点击该链接,绕过该页面的缓存?

好看的东西像&LT;一个bypassCache HREF =方式&gt; 将是一厢情愿的想法。


解决方案

  

一件好事就像是一厢情愿的想法。


事实上,有一些东西你可以从链接中做到:添加一个随机的GET参数

 &LT; A HREF =htt​​p://example.com/myfile.txt?a=193834923283943842923&gt;查看&LT;!/ A&GT;

您可以使用JavaScript(或当然的服务器端脚本语言如PHP)来这样做一个动态的基础上。

然而,远优于方法是在服务器侧的第一位置正确地配置的文本文件的缓存头。盗窃最好办法头信息来禁用客户端缓存,.htaccess文件像这应该工作:

 &LT;文件myfile.txt的&GT;
FileETag无
&LT; IfModule mod_headers.c&GT;
头取消设置的ETag
头设置缓存控制专卖店,无缓存,必重新验证,检查后= 0,pre-检查= 0
头设置语用无缓存
头中设置过期孙,1978年11月19日05:00:00 GMT
&LT; / IfModule&GT;
&LT; / FilesMatch&GT;

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?

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

解决方案

Something nice like would be wishful thinking.

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>

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

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天全站免登陆