gpt4 book ai didi

asp.net - 在网站的过期 header 中设置多长时间比较合适?

转载 作者:行者123 更新时间:2023-12-02 06:38:41 25 4
gpt4 key购买 nike

"Web pages are becoming increasingly complex with more scripts, style sheets, images, and Flash on them. A first-time visit to a page may require several HTTP requests to load all the components. By using Expires headers these components become cacheable, which avoids unnecessary HTTP requests on subsequent page views. Expires headers are most often associated with images, but they can and should be used on all page components including scripts, style sheets, and Flash."

正如Yslow中所写。

我的问题是,对于具有多个样式表、Flash header 、Javascript、图像、PDF、MS Excel 文件、PPT 等的网站,在过期 header 中设置多长时间比较合适?

如果我想对所有内容设置相同的过期时间。

最佳答案

我所做的是将 CSS 和 JavaScript 文件的过期时间设置为一个较高的值,例如 1 或 5 年。当我更改样式表或 JS 文件时,我会更改其 URL 中的版本号,以防止从缓存中提供过时的文件。

看起来这也是SO所做的:

<link rel="stylesheet" href="http://sstatic.net/stackoverflow/all.css?v=e27c9b7474df">

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<script src="http://sstatic.net/js/question.js?v=b05e8725a843" type="text/javascript"></script>

因此,当他们更改样式表时,他们会将 all.css?v=e27c9b7474df 更改为 all.css?v=some new versionquestion.js javascript 文件遵循相同的约定。但文件名也可以,你可以将 CSS/JS 文件命名为 all-1.css,然后将其更改为 all-2.css 等。实际格式为只要 URL 发生变化,版本号就由您决定。

关于asp.net - 在网站的过期 header 中设置多长时间比较合适?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3362511/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com