2012-02-16 149 views
0

我们有一些经常更新的页面。然而,图像被缓存,有时,旧的横幅/图像是被某些人看到的。这是至关重要的,因为一些横幅包含1天的促销活动。如果较旧的图像是被查看的图像,那么我们无法向他们传达关于促销的信息。有没有办法告诉浏览器在加载页面时清除缓存?

这也发生在CSS上。有时,我们更新CSS,但即使在刷新几次之后,旧的CSS仍然是正在加载的CSS。

有没有办法来防止这些事情发生?

+0

您使用哪种服务器端脚本语言? – jerjer 2012-02-16 06:39:58

+0

我们正在使用PHP。 – catandmouse 2012-02-16 06:44:21

+0

请参阅下面的答案 – jerjer 2012-02-16 06:55:41

回答

0

使用此代码,如果使用C#的工作

// Disable CACHE of browser 
      //System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); 
      //System.Web.HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
      //System.Web.HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); 
      //System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache); 
      //System.Web.HttpContext.Current.Response.Cache.SetNoStore(); 
1

请尝试以下应该防止图像和CSS从缓存中你可以这样做:

<img src="some.gif?t=<?php echo uniqid();?>" /> 
<link href="some.css?t=<?php echo uniqid();?>" /> 
相关问题