and*_*rew 229 http browser-cache
如何为我的网站启用浏览器缓存?我只是把cache-control:public放在我的标题中的某个地方吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
Cache-Control:public;
>
Run Code Online (Sandbox Code Playgroud)
我正在使用最新版本的XAMPP开发最新版本的PHP.
Cod*_*nci 191
要在HTML中使用缓存控件,请使用元标记,例如
<meta http-equiv="Cache-control" content="public">
Run Code Online (Sandbox Code Playgroud)
内容字段中的值定义为以下四个值之一.
Cache-Control标题的一些信息如下
HTTP 1.1.允许值= PUBLIC | 私人| NO-CACHE | NO-STORE.
公共 - 可以缓存在公共共享缓存中.
私有 - 只能缓存在私有缓存中.
无缓存 - 可能无法缓存.
No-Store - 可以缓存但不归档.指令CACHE-CONTROL:NO-CACHE表示不应使用缓存信息,而是应将请求转发到源服务器.该指令与PRAGMA具有相同的语义:NO-CACHE.
客户端应该包括PRAGMA:NO-CACHE和CACHE-CONTROL:NO-CACHE,当无缓存请求被发送到不知道是HTTP/1.1兼容的服务器时.另见EXPIRES.
注意:在HTTP中指定缓存命令可能比在META语句中更好,在META语句中,它们可以影响比浏览器更多,但代理和其他可能缓存信息的中介.
scu*_*ffe 129
您可以使用以下方法在PHP中设置标题:
<?php
//set headers to NOT cache a page
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
//or, if you DO want a file to cache, use:
header("Cache-Control: max-age=2592000"); //30days (60sec * 60min * 24hours * 30days)
?>
Run Code Online (Sandbox Code Playgroud)
请注意,使用的确切标头将取决于您的需求(如果您需要支持HTTP 1.0和/或HTTP 1.1)
小智 44
正如我所写(在http://www.williamferreira.net/blog/2011/10/04/controle-de-cache-apache/),最好使用.htacces文件.但请注意将内容留在缓存中的时间.
使用:
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
其中:604800 = 7天
PS:这可用于重置任何标头
ang*_*iwi 29
http://www.askapache.com/htaccess/apache-speed-cache-control.html上的页面建议使用以下内容:
添加缓存控制标头
这是你的根.htaccess文件,但如果你有权访问httpd.conf更好.
此代码使用FilesMatch指令和Header指令将Cache-Control Headers添加到某些文件.Run Code Online (Sandbox Code Playgroud)# 480 weeks <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=290304000, public" </FilesMatch>
Eri*_*cía 19
这是.htaccess我在我的实际网站中使用的最好的:
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
##Tweaks##
Header set X-Frame-Options SAMEORIGIN
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_headers.c>
Header set Connection keep-alive
<filesmatch "\.(ico|flv|gif|swf|eot|woff|otf|ttf|svg)$">
Header set Cache-Control "max-age=2592000, public"
</filesmatch>
<filesmatch "\.(jpg|jpeg|png)$">
Header set Cache-Control "max-age=1209600, public"
</filesmatch>
# css and js should use private for proxy caching https://developers.google.com/speed/docs/best-practices/caching#LeverageProxyCaching
<filesmatch "\.(css)$">
Header set Cache-Control "max-age=31536000, private"
</filesmatch>
<filesmatch "\.(js)$">
Header set Cache-Control "max-age=1209600, private"
</filesmatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</filesMatch>
</IfModule>
Run Code Online (Sandbox Code Playgroud)
Pet*_*aný 13
对于Apache服务器,您应该检查mod_expires以设置Expires和Cache-Control标头.
或者,您可以使用Header指令自行添加Cache-Control:
Header set Cache-Control "max-age=290304000, public"
Run Code Online (Sandbox Code Playgroud)
元缓存控制标记允许Web发布者定义缓存应如何处理页面.它们包括声明应该可缓存的指令,缓存可以存储的内容,到期机制的修改以及重新验证和重新加载控制的指令.
允许的值是:
公共 - 可以缓存在公共共享缓存中
私有 - 可能只缓存在私有缓存中
无缓存 - 可能不缓存
无存储 - 可能缓存但不存档
区分大小写请注意.在您的网页来源中添加以下元标记.标记末尾的拼写差异是您使用"/> = xml"或"= = html".
<meta http-equiv="Cache-control" content="public">
<meta http-equiv="Cache-control" content="private">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="no-store">
Run Code Online (Sandbox Code Playgroud)
来源 - > MetaTags
OWASP建议如下,
只要有可能,请确保缓存控制HTTP标头设置为no-cache,no-store,must-revalidate,private; 并且pragma HTTP标头设置为no-cache.
<IfModule mod_headers.c>
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</IfModule>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
638903 次 |
| 最近记录: |