What's the difference Expires and Cache-control:max-age?

守給你的承諾、 提交于 2019-11-29 11:59:29

问题


Could you tell me the difference of Expires and Cache-control:max-age?


回答1:


Expires was defined in the HTTP/1.0 specifications, and Cache-Control in the HTTP/1.1 specifications.

I would suggest defining both so you cater to both, the older clients that only understand HTTP/1.0, and the newer ones.




回答2:


Expires was specified in HTTP 1.0 specification as compared to Cache-Control: max-age, which was introduced in the early HTTP 1.1 specification. The value of the Expires header has to be in a very specific date and time format, any error in which will make your resources non-cacheable. The Cache-Control: max-age header's value when sent to the browser is in seconds, the chances of any error happening in which is quite less.

Since you can specify only one of the two headers in your web.config file, I'd suggest going with the Cache-Control: max-age header because of the flexibility it offers in setting a relative timespan from the present date to a date in the future. You can basically set and forget, as compared to the case with Expires header, whose value you will have to remember to update at least once every year. And if you set both headers programmatically from within your code, know that the value of Cache-Control: max-age header will take precedence over Expires header. So, something to keep in mind there as well.

From Setting Expires and Cache-Control: max-age headers for static resources in ASP.NET



来源:https://stackoverflow.com/questions/5946894/whats-the-difference-expires-and-cache-controlmax-age

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!