cache-control

Laravel移除Cache-Control

我们两清 提交于 2019-12-01 16:30:42
碰到一个问题,网站上线后,需要移除Cache-Control,就是下面这个东西 方案1 失败 参考网址: https://stackoverflow.com/questions/51821563/laravel-5-how-to-set-cache-control-http-header-globally 修改 RouteServiceProvider.php protected function mapWebRoutes() { Route::middleware('web') ->middleware('cache.headers:private;max_age=3600') // added this line ->namespace($this->namespace) ->group(base_path('routes/web.php')); } 方案2 失败 修改.htaccess文件。添加如下内容 注意:需要apache开启mod_headers,否则可能出现500错误 <IfModule mod_headers.c> Header unset Cache-Control </IfModule> 方案3 成功 新建中间件 php artisan make:middleware CheckResponse 修改handle方法如下 public function

What does `expires -1` mean in NGINX `location` directive?

大憨熊 提交于 2019-12-01 15:27:35
问题 Given the sample location example below, what does -1 mean for expires ? Does that mean "never expires" or "never caches"? # cache.appcache, your document html and data location ~* \.(?:manifest|appcache|html?|xml|json)$ { expires -1; access_log logs/static.log; } https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/expires.conf 回答1: According to nginx manual, this directive adds the Expires and Cache-Control HTTP header to the response. Value -1 means these headers are set

对前端缓存的研究--------引用

寵の児 提交于 2019-12-01 15:22:56
大家都知道缓存的英文叫做 cache。但我发现一个有趣的现象:这个单词在不同人的口中有不同的读音。为了全面了解缓存,我们得先从读音开始,这样才能够在和其他同事(例如 PM)交(zhuāng)流(bī)时体现自己的修(bī)养(gé) 基本的网络请求就是三个步骤:请求,处理,响应。 后端缓存主要集中于“处理”步骤,通过保留数据库连接,存储处理结果等方式缩短处理时间,尽快进入“响应”步骤。 而前端缓存则可以在剩下的两步:“请求”和“响应”中进行。在“请求”步骤中,浏览器也可以通过存储结果的方式直接使用资源,直接省去了发送请求;而“响应”步骤需要浏览器和服务器共同配合,通过减少响应内容来缩短传输时间。 按缓存位置分类 缓存的文章会直接从 HTTP 协议头中的缓存字段开始,例如 Cache-Control, ETag, max-age 等。但偶尔也会听到别人讨论 memory cache, disk cache 等。 实际上,HTTP 协议头的那些字段,都属于 disk cache 的范畴,是几个缓存位置的其中之一。因此本着从全局到局部的原则,我们应当先从缓存位置开始讨论。等讲到 disk cache 时,才会详细讲述这些协议头的字段及其作用。 Network -> Size 一列看到一个请求最终的处理方式:如果是大小 (多少 K, 多少 M 等) 就表示是网络请求,否则会列出 from

浏览器 HTTP 协议缓存机制详解

孤者浪人 提交于 2019-12-01 15:06:05
最近在准备优化日志请求时遇到了一些令人疑惑的问题,比如为什么响应头里出现了两个 cache control、为什么明明设置了 no cache 却还是发请求,为什么多次访问时有时请求里带了 etag,有时又没有带?等等。。。 后来查了一些资料以及同事亲自验证,总算对这些问题有了个清晰的理解,现在整理出来以备忘。 1、缓存的分类 缓存分为服务端侧(server side,比如 Nginx、Apache)和客户端侧(client side,比如 web browser)。 服务端缓存又分为 代理服务器缓存 和 反向代理服务器缓存(也叫网关缓存,比如 Nginx反向代理、Squid等),其实广泛使用的 CDN 也是一种服务端缓存,目的都是让用户的请求走”捷径“,并且都是缓存图片、文件等静态资源。 客户端侧缓存一般指的是浏览器缓存,目的就是加速各种静态资源的访问,想想现在的大型网站,随便一个页面都是一两百个请求,每天 pv 都是亿级别,如果没有缓存,用户体验会急剧下降、同时服务器压力和网络带宽都面临严重的考验。 2、 浏览器缓存机制 详解 浏览器缓存控制机制有两种:HTML Meta标签 vs. HTTP头信息 2.1 HTML Meta标签控制缓存 浏览器缓存机制,其实主要就是HTTP协议定义的缓存机制(如: Expires; Cache-control等)

spring security - how to remove cache control in certain url pattern

假如想象 提交于 2019-12-01 11:21:47
I am trying to filter some url pattern to caching. What I have attempted is put some codes into WebSecurityConfigurerAdapter implementation. @Override protected void configure(HttpSecurity http) throws Exception { initSecurityConfigService(); // For cache http.headers().defaultsDisabled() .cacheControl() .and().frameOptions(); securityConfigService.configure(http,this); } However this code will effect all of the web application. How can I apply this to certain URL or Content-Type like images . I have already tried with RegexRequestMatcher , but it does not work for me. // For cache http

Nginx Cache-Control

痴心易碎 提交于 2019-12-01 08:06:13
转自: https://www.cnblogs.com/sfnz/p/5383647.html HTTP协议的Cache-Control指定请求和响应遵循的缓存机制。 在请求消息或响应消息中设置 Cache-Control并不会影响另一个消息处理过程中的缓存处理过程。 请求时的缓存指令包括no-cache、no-store、max-age、 max-stale、min-fresh、only-if-cached等。 响应消息中的指令包括public、private、no-cache、no- store、no-transform、must-revalidate、proxy-revalidate、max-age。 浏览器中关于Cache 的3 属性: Cache-Control: 设置相对过期时间, max-age指明以秒为单位的缓存时间. 若对静态资源只缓存一次, 可以设置max-age的值为315360000000 (一万年). Http 协议的cache-control 的常见取值及其组合释义: no-cache: 数据内容不能被缓存, 每次请求都重新访问服务器, 若有max-age, 则缓存期间不访问服务器. no-store: 不仅不能缓存, 连暂存也不可以(即: 临时文件夹中不能暂存该资源) private(默认): 只能在浏览器中缓存, 只有在第一次请求的时候才访问服务器,

Why doesn't Safari honor my cache-control directive?

霸气de小男生 提交于 2019-12-01 03:54:29
There is a particular page that I would like the browser to always load, particularly when the user presses the browser back button to get to it. So I use the following 'Cache-Control' directive in the header for this page (taking the PHP directly from my code). $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; This works for FF, IE and Chrome, but Safari (5.0.1) seems to ignore the directive and fails to reload the page (across multiple users, so it doesn't seem to be a setup specific problem). Searching hasn't revealed any known bugs, so I'm assuming there is

tomcat security-constraint impact cache

家住魔仙堡 提交于 2019-12-01 03:20:37
I have a problem in caching my application. when this code is added to web.xml of tomcat : <security-constraint> <web-resource-collection> <web-resource-name>HTTPSOnly</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> I get this response : Cache-Control private Date Tue, 18 Feb 2014 01:18:17 GMT Etag W/"200-1391558564593" Expires Thu, 01 Jan 1970 00:00:00 WET Server Apache-Coyote/1.1 Without this code everything is fine : Accept-Ranges bytes

浅谈浏览器的缓存机制

只愿长相守 提交于 2019-12-01 00:25:45
浏览器的缓存可分为HTTP缓存和离线缓存,下面将分别介绍 HTTP缓存 只有GET请求能被缓存,POST不能被缓存。 Modified Time/ETag/Expires/Cache都是HTTP协议的缓存策略 先来一个例子 当我们第二次访问百度首页,在Chrome的Network面板中打开一个静态文件时会发现响应的status是: 200 OK (from disk cache) ,不是应该返回304 Not Modified吗?如果你知道答案,那就可以忽略本文了。 Cache-Control 简介 w3.org 的定义是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 这是一个通用首部字段(就是请求报文和响应报文都能用上的字段),用来控制HTTP缓存的行为。 例如: Cache-Control: max-age=3600, public public 意味着这个响应可以被任何人缓存 max-age 则表明了该缓存有效的秒数,允许你的网站被缓存将大大减少下载时间和带宽,同时也提高浏览器的载入速度。 也可以通过设置 no-cache

浅谈浏览器的缓存机制

允我心安 提交于 2019-11-30 21:14:14
浏览器的缓存可分为HTTP缓存和离线缓存,下面将分别介绍 HTTP缓存 只有GET请求能被缓存,POST不能被缓存。 Modified Time/ETag/Expires/Cache都是HTTP协议的缓存策略 先来一个例子 当我们第二次访问百度首页,在Chrome的Network面板中打开一个静态文件时会发现响应的status是: 200 OK (from disk cache) ,不是应该返回304 Not Modified吗?如果你知道答案,那就可以忽略本文了。 Cache-Control 简介 w3.org 的定义是:“The Cache-Control general-header field is used to specify directives which MUST be obeyed by all caching mechanisms along the request/response chain.” 这是一个通用首部字段(就是请求报文和响应报文都能用上的字段),用来控制HTTP缓存的行为。 例如: Cache-Control: max-age=3600, public public 意味着这个响应可以被任何人缓存 max-age 则表明了该缓存有效的秒数,允许你的网站被缓存将大大减少下载时间和带宽,同时也提高浏览器的载入速度。 也可以通过设置 no-cache