Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在缓存中加载了一个 js 文件。
当在浏览器中加载 html 文件时,它会向服务器发送条件请求(从此处找到)以检查该资源是否已更改。
我想要做的是在资源被缓存时不要向服务器发送任何请求(既不是条件请求也不是新请求)。
可能吗?
如果可能的话,有什么解决方案?
如果不是为什么?
是的,当然可以告诉浏览器您的内容不会改变,因此它不需要发出请求。您应该使用 Cache-Control 标头的 max-age 参数或 Expires 标头。这篇之前的 StackOverflow帖子讨论了使用每种方法的优缺点。