我正在建立一个网站,其中各种css精灵使用。但我的问题是,当我对上传的图像进行任何更改时,有时它不会反映在客户端浏览器上,因为有时页面及其数据,如css,图像,javascripts是从浏览器缓存中加载的。
在这种情况下,请建议我怎么做。我应该把这些放在
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>在HTML页面中?
或者有什么想法来解决这个问题?
发布于 2014-06-05 11:55:22
当我处理网页中的动态图像时,我总是在URL的末尾添加一个带有随机值的参数,以强制浏览器(尤其是IE)从服务器检索最新的图像。
image.jpg?v=<random num>-<random num>-<random num>-<random num>您的图像url将如下所示
src="image.jpg?v=1234-5678-91011"我通过Javascript控制的随机数。当然,任何随机参数值约定都可以,这只是我喜欢的格式。希望这能有所帮助。
发布于 2014-06-05 12:12:44
在Chrome....this上以匿名模式查看时,要求您的客户查看您的更改应该可以解决问题……
发布于 2014-06-05 12:51:33
change the name of the picture each time you upload or add a random number to it
src="myimage.jpg?{somerandomnumber}" 或
用于在所有浏览器中关闭缓存的标记 Useful HTML Meta Tags
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />你的.htaccess文件。
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 days"
</IfModule>
## EXPIRES CACHING ##https://stackoverflow.com/questions/24051311
复制相似问题