是的,我在这里和那里搜索了很多,这是我发现的最接近我认为可以实际工作的.但事实并非如此.
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|x-icon|js|css|jpg|jpeg|png|gif|swf|pdf)$">
Header unset Cookie
Header unset Set-Cookie
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
非常清楚它应该是我尝试cookie释放子域提供的静态文件,并删除这些静态文件上的ETag标头.ETag的工作正常,但我无法取消设置cookie.
仅供参考,Wordpress安装在example.com上(不是www.example.com; www.example.com重定向到example.com),这不是无cookie的.i.example.com提供静态文件.我想让i.example.com无cookie.当非www tld不是无cookie时,是否可以使子域无cookie?(我也看到这就是许多人建议使用www.tld的原因).
我在这里已经回答了 100 多个答案,有很多尝试,没有任何效果??
有一个基于 PHP 的站点。我需要为所有 .php 文件关闭缓存,除了少数几个。
所以,在 .htaccess 中,我有以下内容:
ExpiresActive On
# Eliminate caching for certain dynamic files
<FilesMatch "\.(php|cgi|pl)$">
ExpiresDefault A0
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
使用 Firebug,我看到以下内容:
Cache-Control no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, no-transform
Connection Keep-Alive
Content-Type text/html
Date Sun, 02 Sep 2012 19:22:27 GMT
Expires Sun, 02 Sep 2012 19:22:27 GMT
Keep-Alive timeout=3, max=100
Pragma no-cache
Server Apache
Transfer-Encoding chunked
X-Powered-By PHP/5.2.17
Run Code Online (Sandbox Code Playgroud)
嘿,看起来很棒!
但是,我有几个 .php 页面,我需要一些非常短的缓存。 …
我正在调试localhost上的js代码,我需要阻止浏览器缓存文件.我无法使用附加到网址的时间戳,因为它会删除Chrome调试器断点.
通常我不必刷新缓存,但我会做一段时间.这是一个很大的问题,因为我去别处寻找bug.我前段时间将此代码添加到apache:
<IfModule mod_headers.c>
Header add Expires "Sun, 19 Nov 1978 05:00:00 GMT"
Header add Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
</IfModule>
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么Apache会误认为某个文件有效,或者为配置代码提供一些可以一劳永逸地解决这个问题的补充吗?
使用以下解决方案的标头:
<IfModule mod_expires.c>
expiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType text/html "access plus 1 seconds"
ExpiresByType text/javascript "access plus 1 seconds"
ExpiresByType application/x-javascript "access plus 1 seconds"
</IfModule>
http://localhost/static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png
GET /static/images/%d0%9a%d0%be%d0%bf%d0%b8%d1%8f%20logo_inner.png HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://localhost/static/images/
Cache-Control: max-age=0 …Run Code Online (Sandbox Code Playgroud) 我有一个名为icons.png的 PNG 文件托管在apache服务器上。基本上这个文件是其他小图像元素(CSS Sprite)的组合。当页面第一次加载时,此文件会以正常的200 OK响应加载。
页面加载后;有一些链接悬停在其上触发自定义工具提示。此工具提示将icons.png文件中的部分图像显示为某些HTML 元素的背景图像。
例如 HTML 代码是这样的:
jQuery(".profile").tipTip({delay: 200, defaultPosition: "top", content: "<a href='#' style='width: 32px; height: 32px; display: block; 背景:网址(图像/图标.png) no-repeat -200px -64px'></a>"});
[HTML 文件中还有一些其他地方引用了icons.png ]
现在,每次我将鼠标悬停在链接上时,都会显示工具提示,但同时浏览器会向服务器发送一个 HTTP 请求以获取icons.png文件。来自服务器的响应代码是304 Not Modified。
虽然没有获取文件的内容,但是每次发送标头(大约 166 字节)的开销仍然存在,这反过来又导致了1.5 秒的延迟(我的连接速度很慢)。在这段 1.5 秒的时间里,工具提示元素没有背景图像 & 突然图像突然出现。
这是一些屏幕截图
客户端是否可以使用 JavaScript 覆盖和/或忽略动态加载内容(例如异步加载的图像)的 HTTP Cache-Control 标头?
我的基于 JavaScript 的 GIS 应用程序从外部服务器动态请求图像,该服务器发送以下标头及其响应:
Cache-Control:max-age=0,must-revalidate
Run Code Online (Sandbox Code Playgroud)
这会导致浏览器发送对相同图像的重复请求(以及 If-None-Match 请求标头),这总是导致 HTTP 304 Not Modified 响应,因此无论如何都会使用缓存,但只会在延迟之后使用。
我已经知道图像没有改变,但我无法控制服务器发送的缓存控制标头,所以我想在显示图像时强制使用本地浏览器缓存,而不必先重新验证服务器。
是否可以在客户端更改此设置?
我正在编写一个 Web 应用程序框架。为了正确支持反向代理服务器,我想确保每当 Web 应用程序访问 cookie 数据时,发送给用户的页面只会为该用户缓存。据我所知,有两种方法可以实现这一点:
header('Vary: Cookie');
Run Code Online (Sandbox Code Playgroud)
或者
header('Cache-Control: private');
Run Code Online (Sandbox Code Playgroud)
使用的直接好处Vary: Cookie是反向代理服务器将缓存未经身份验证的请求。但是,我们正在使用通过 javascript 创建 cookie 的 Google Analytics - 所以我担心 Vary: Cookie 方法不可用?
问题:即使在注销后,点击浏览器中的后退按钮也会呈现安全页面的缓存版本。
我正在尝试使用FOSHttpCacheBundle. 这是我的配置:
fos_http_cache:
cache_control:
defaults:
overwrite: true
rules:
-
match:
path: ^/
headers:
cache_control: { no_cache: true }
Run Code Online (Sandbox Code Playgroud)
虽然可以设置Cache-Control:no-cache, private但没有Pragma: no-cache和Expires: -1头文件中定义了根据文档应当被定义。
这是我的响应标头:
Cache-Control:no-cache, private
Connection:Keep-Alive
Content-Type:text/html; charset=UTF-8
Date:Tue, 03 May 2016 09:03:49 GMT
Keep-Alive:timeout=5, max=95
Server:Apache/2.4.9 (Win64) PHP/5.5.12
Transfer-Encoding:chunked
X-Cache-Debug:1
X-Debug-Token:050e09
X-Debug-Token-Link:/app_dev.php/_profiler/050e09
X-Powered-By:PHP/5.5.12
Run Code Online (Sandbox Code Playgroud)
有人请解释我错过了什么!!
谢谢
caching cache-control browser-cache symfony foshttpcachebundle
我正在 Tomcat 的 web.xml 中设置过期过滤器。标头正确响应,但 IE 仍未缓存。它总是向 Tomcat 发出新的请求。
<filter>
<filter-name>ExpiresFilter</filter-name>
<filter-class>org.apache.catalina.filters.ExpiresFilter</filter-class>
<init-param>
<param-name>ExpiresByType image/png</param-name>
<param-value>access plus 2 hours</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ExpiresFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
以下是响应的标题
缓存控制:max-age=7199
到期时间:2016 年 11 月 14 日星期一 16:08:22 GMT
内容类型:图像/png
传输编码:分块
日期:2016 年 11 月 14 日星期一 14:08:22 GMT
有谁知道,我在这里错过了什么?
我是SpringBoot的新手。
我基于Springboot的示例项目来创建我的项目。我想仅针对js / css文件控制用于缓存的http标头。
我在下面添加了一个js文件test.js,src/resources/static然后在中引用它greeting.html。
然后,我在StackOverflow上遵循一些答案,并添加WebMvcConfiguration.java和WebSecurityConfig.java,但它对我不起作用。
我确定WebMvcConfiguration和WebSecurityConfig不应一起使用,或者我配置有误。我更喜欢使用Java Config而不是XML的解决方案。
我打开ChromeDevTool来检查服务器的响应。响应http标头是
Accept-Ranges:bytes
Cache-Control:no-store
Content-Length:20
Content-Type:application/javascript
Date:Thu, 02 Feb 2017 10:53:14 GMT
Expires:
Last-Modified:Thu, 02 Feb 2017 10:52:49 GMT
Pragma:
Run Code Online (Sandbox Code Playgroud)
谢谢!
更新:当我删除时WebSecurityConfig,我得到以下标题
Accept-Ranges:bytes
Cache-Control:no-store
Content-Length:20
Content-Type:application/javascript
Date:Thu, 02 Feb 2017 11:14:51 GMT
Last-Modified:Thu, 02 Feb 2017 11:14:20 GMT
Run Code Online (Sandbox Code Playgroud)
greeting.html
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Getting Started: Serving Web Content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script th:src="@{/test.js}"></script>
</head> …Run Code Online (Sandbox Code Playgroud) 我当前的项目几乎可以使用以下配置:
root %%COMP_WEB_ROOT;
# COMP Static File serving
location /comp {
alias %%COMP_WEB_ROOT;
try_files $uri$args $uri$args/ /index.html;
add_header 'Cache-Control' 'no-cache, no-store, must-revalidate';
}
# Hide the index file, not exposing that path specifically
location = /index.html {
internal;
}
Run Code Online (Sandbox Code Playgroud)
这样,我就防止了整个应用程序的缓存,这是不希望的,因为我只想防止index.html页存储缓存。
所以我试图将add_header线像这样放置在第二个块内:
root %%COMP_WEB_ROOT;
# COMP Static File serving
location /comp {
alias %%COMP_WEB_ROOT;
try_files $uri$args $uri$args/ /index.html;
error_page 401 = @error401web;
}
# Hide the index file so that we're not exposing that path specifically
location = /index.html …Run Code Online (Sandbox Code Playgroud) cache-control ×10
caching ×6
apache2 ×1
cookies ×1
http-headers ×1
javascript ×1
nginx ×1
php ×1
spring-boot ×1
symfony ×1
tomcat ×1
vary ×1