有人可以澄清一下缓存是如何工作的吗? 或者它完全取决于浏览器?
<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.
更多推荐
发布评论