dongyi2159 2012-03-26 10:59
浏览 73

如何使用缓存过期?

I use Speed Up to check the speed of my website and it gives some tips like: "Optimizing Cache". I found some info on yahoo.com like ExpiresDefault "access plus 10 years"

Should I put that rule in the .htaccess?

And another question, should I use that for my website? it's totally not static, it's a very complex browser game with dynamic pages. I found this link: http://www.askapache.com/hacking/speed-site-caching-cache-control.html

But when I cache the media files for one year, and then I update an image, it is not visible for the users for one year?

  • 写回答

1条回答 默认 最新

  • dtsps2098 2012-03-26 11:04
    关注

    The html5 boilerplate project has extensive docs on setting up cache headers, and using the standard htaccess file which comes with the project on it's own can give you a great foundation in setting up cache headers correctly.

    Cache headers define how long a user can download a file and expect the contents to be fresh. As such you should use short or no cache expiry for dynamic pages. Usually a short expiry for dynamic content is merely a means of managing server load - i.e. you only add short expiry when you're at the point of wanting/needing to reduce communication with your server.

    For any url with a long cache expiry, when the contents change so should the url. so

    /img/sprite.png
    

    if you modify that file, make it:

    /img/sprite_<x>.png
    

    where x is whatever you like - e.g. the date 20120326HHMM

    If you use a build process, the above can be automated such that you don't have to think about it. That's also something that's covered at length in the html5 boilerplate docs.

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题