0

我正在尝试遵循 YSLOW 的指南来优化我的网站。我注意到,当图像、js 和 css 文件等静态内容托管在我的主域上时,它们会与不必要的 cookie 一起下载。因此,我将它们放在一个新域(而不是子域)上以避免这种情况。

然后我发现 YSLOW 说这个静态内容需要很久以后过期的标头。这不会导致cookies被启用吗?这是非此即彼的情况,还是可以在无 cookie 的域上托管静态内容并添加过期标头?如果是这样,怎么做?

4

1 回答 1

3

Cookies are not expire headers. Cookies are set with the Set-Cookie HTTP header, which specifically instructs the browser to save a small piece of text and send it again every time it contacts the same domain. Expire headers are set with the Expires and related headers and tell the browser when the content should be regarded as expired. This causes the browser to not contact the server at all and cache the data locally.

They're both entirely separate headers and mechanisms. See here for a list of all the other headers you can send and their effect, and use your browsers inspector's network tab to have a look at what kind of headers are being sent back and forth on each request.

于 2013-08-25T13:25:01.230 回答