控制浏览器缓存 [英] controlling browser cache

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

问题描述

假设我在页面中有一大堆图像,然后我去了一个不同的url,它具有完全相同的图像和布局,因为url是不同的浏览器将重新加载所有图像,布局等,不会显示他们从缓存,即使他们是完全相同的图像/布局....

有没有一种方法来防止这种情况,并控制浏览器缓存事物的方式javascript,php或html?

编辑/加法

有趣的是,首先我有两个同一站点的副本,一个在我的本地服务器上,另一个在远程托管服务器上....... $ /

本地服务器上的缓存完美缓存,并且没有任何图像会重新出现,而如果我访问远程服务器上的图像,图像将尝试重新出现....尽管文件等实际上是虚拟的在本地和远程服务器之间是相同的......



编辑/添加



另一个有趣的事情是......即使是远程服务器,缓存也可以在IE和Chrome上运行,但由于某种原因,它会在Firefox中搞砸了......



另一方面,本地服务器中的一个可以工作,即使是Firefox也是如此。

解决方案

< (Cache-Control:private,max-age = 5400)使用头文件请求浏览器缓存不起作用

  ,预检= 5400); 
header(Pragma:private);
header(Expires:。gmdate(D,d M Y H:i:s)。GMT);

有一个很好的网站来检查返回的标题 http://redbot.org 试试看,它可能会帮助你加上theres http ://www.mnot.net/cache_docs/ 你可能想看看,如果你不揣测你的答案。


so suppose i have a whole bunch of images in a page, and then I go to a different url that has the exact same images and layout, since the url is different the browser will reload all images,layout etc and will not display them from the cache even though they are the exact same images/layout....

is there a way to prevent this and control the way browser caches things using only javascript, php, or html?

EDIT/Addition

also what's interesting is that first of all I have two copies of the same site, one on my local server and another one on a remote hosting server.....

the one on the local server caches perfectly and none of the images reappear, whereas if I access the one on the remote server, the images would try to reappear....despite the fact that the files,etc are virtually identical between the local and remote server...

EDIT/Addition

Another interesting thing....the caching would work on IE and Chrome even for the remote server, but for some reason, it would screw up in firefox....

on the other hand the one in the local server would work even for firefox

解决方案

would asking the browser cache by using headers not help

    header("Cache-Control: private, max-age=5400, pre-check=5400");
    header("Pragma: private");
    header("Expires: " . gmdate("D, d M Y H:i:s"). " GMT");

there a good site to check returned headers http://redbot.org try it out it may help plus theres http://www.mnot.net/cache_docs/ you may want to look at if you dont figger your answer.

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

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