V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
iugo
V2EX  ›  问与答

怎样给网站的一些图片标注过期日期以利浏览器缓存? Leverage browser caching

  •  
  •   iugo · 2011-04-05 23:46:26 +08:00 · 4635 次点击
    这是一个创建于 4769 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Google 原文:
    Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

    我参看了 http://code.google.com/intl/zh-CN/speed/page-speed/docs/caching.html ,但还是不懂。
    英语比较不好,该自己搜索的都自己搜索了下。但没找到应用实例。。。

    求助怎样解决图片 expiration not specified 问题。
    这个过期时间是统一标注在 head 还是要每个图片都注明,或者在 css 中?要怎样写?
    4 条回复    1970-01-01 08:00:00 +08:00
    predator
        1
    predator  
       2011-04-06 00:03:21 +08:00 via Android
    写在web server的配置里面。一般是对一个目录下的文件进行指定。

    例如,唯一文件名的用户上传文件,给最大的expire时间,半年一年都可以。js, css,页面布局相关图片之类,就相对设短一些,特别是开发中的网站—这些文件会频繁更新。
    iugo
        2
    iugo  
    OP
       2011-04-06 00:47:10 +08:00
    @predator web server的配置? 可是我使用的是虚拟主机,不能操作服务器. Google 上说可以写在 the HTTP headers 中,不知道能实现不?
    raptium
        3
    raptium  
       2011-04-06 01:12:04 +08:00 via iPhone
    是在 http headers 里的
    问题是图片是静态文件 header 是 web server 决定的 除非你用动态的脚本来 serve 静态内容 但这样服务器性能会有影响
    不知道你所谓不能操作服务器究竟局限到何种程度 expire 设置说不定在 htaccess 里就能指定吧
    iugo
        4
    iugo  
    OP
       2011-04-06 03:57:12 +08:00
    @raptium 谢谢. 看了您的提示, 我找到了一种相关方法 mod_expires .
    http://kevin.vanzonneveld.net/techblog/article/control_cache_expire_dates_using_htaccess/
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5431 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:33 · PVG 15:33 · LAX 00:33 · JFK 03:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.