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.

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode问题请教
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM