gpt4 book ai didi

http - 如何指示浏览器在缓存资源时忽略 GET 参数

转载 作者:可可西里 更新时间:2023-11-01 15:18:09 26 4
gpt4 key购买 nike

有没有办法(一个http头)告诉浏览器在执行缓存时不要区分main.cssmain.css?someparam=1

根据 w3c spec :

since some applications have traditionally used GETs and HEADs with query URLs (those containing a "?" in the rel_path part) to perform operations with significant side effects, caches MUST NOT treat responses to such URIs as fresh unless the server provides an explicit expiration time. This specifically means that responses from HTTP/1.0 servers for such URIs SHOULD NOT be taken from a cache

如果 GET 参数发生变化,我的 Firefox 3.5.5 会重新从服务器获取文件。如果它没有改变,它会从缓存中获取内容。 (用 FireBug 验证)。

那么,有没有办法解决这个问题(无需删除 get 参数)。

最佳答案

不太清楚哪一方需要 URL 中的参数:服务器还是客户端?不管怎样,你的服务器可以让客户端处理相同的 URL,并且不需要任何不存在的魔术头。 ;)

如果服务器需要参数,您可以使用 Apache URL 重写添加该参数,如果您使用 Apache:

RewriteRule ^style.css$ /style.css?param=1 [L]

Rewrite Engine 还可以做其他事情,您甚至可以通过 cookie 传递参数,并在 RewriteCond 行中将它们提取到查询字符串中:

RewriteCond %{HTTP_COOKIE} a:(.*) # not sure of the syntax
RewriteRule ^style.css$ /style.css?a=%1 [L]

这样,客户端的 URL 将是相同的。

如果客户端发送带有参数的请求,并且它不能以不同的方式工作,你可以放置一个外部重定向并设置一个cookie:

RewriteCond %{QUERY_STRING} a=(.*)
RewriteRule ^(.*)$ /$1 [CO=a:%1:mysite.com,R]

这样浏览器会考虑缓存/不缓存不带任何参数的URL。阅读Rewrite Engine docs ,还有其他有用的功能。

关于http - 如何指示浏览器在缓存资源时忽略 GET 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1877339/

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