在动态文件/网址的情况下缓存如何工作?(How does caching in the case of dynamic files/urls work?)

编程入门 行业动态 更新时间:2024-10-28 00:21:07
在动态文件/网址的情况下缓存如何工作?(How does caching in the case of dynamic files/urls work?)

有人可以澄清一下缓存是如何工作的吗? 或者它完全取决于浏览器?

<script type="text/script" src="/controller/getfoo"> </script>

是一种动态的服务js文件的方式,其中请求被设置为来自控制器的js文件。

<script type="text/script" src="/somewhere/foo.js"> </script>

这是最正常的做法。 在这两种情况下,缓存如何工作?

在案例1中,它会一直发送HTTP请求吗? 但是,这只是在页面加载期间。 如果2浏览器理解文件名是明确提到的,它将检查foo.js是否已在本地可用,否则会发出HTTP请求?

Can someone please clarify how caching works ? Or does it entirely depend on the browser ?

<script type="text/script" src="/controller/getfoo"> </script>

is a dynamic way of serving js file where request is set as a js file from controller .

<script type="text/script" src="/somewhere/foo.js"> </script>

is the most normal way of doing it . How does the caching work in both cases ?

In case 1 it is going to sent a HTTP request all the time ? However that is during the page load only . In case 2 browser understands the file name is mentioned explicitly and it will check if foo.js is already available locally else sents a HTTP request ?

最满意答案

这取决于HTTP服务器的配置方式。 更具体地说,在响应头中,有一个密钥Cache-Control:用于设置此行为。 如果你在getfoo动作响应中将它设置为Cache-Control: no-cache ,那么第一个选项将在每次调用时返回“新的”新数据。

It depends on how the HTTP server is configured. More specifically, in the response header, there's a key Cache-Control: that sets this behaviour. If you set it in your getfoo action response as Cache-Control: no-cache, well, the first option will returns "fresh new" data every time is called.

更多推荐

本文发布于:2023-07-22 02:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1215995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   情况下   网址   文件   动态

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!