eri*_*ric 2 html php caching browser-cache
我想缓存我的所有文件,但我无法弄清楚如何让它工作,以便测试批准.我现在
<meta http-equiv="Cache-Control" content="private" />
<meta http-equiv="Expires" content="86400000" />
<meta http-equiv="Cache-Control" content="max-age=86400000" />
Run Code Online (Sandbox Code Playgroud)
我添加的最后一行只是为了测试是否有过期和max-age会有所帮助(它没有)
我用http://www.webpagetest.org/,https://developers.google.com/pagespeed/#和http://gtmetrix.com/
任何人都可以告诉我如何确保一切都是私人缓存?我检查了一堆其他页面,但没有人提供合法的HTML代码.请列出实际代码,不要只告诉我使用Cache-Control并过期,就像我见过的所有其他网站一样.我真的需要示例代码才能理解.感谢您提前提供的任何帮助.我也在使用PHP,所以如果在header()中这样做,那么也可以.
非常感谢你
编辑:我也尝试使用.htaccess来做到这一点但是没有用.我不知道这是一个设置与我的服务器或什么,但它没有改变任何测试.
在HTML文档中指定到期时间时,它仅适用于实际文档.
假设您已mod_expires
启用Apache Web服务器,您可以创建一个名为的文件.htaccess
并包含以下内容
ExpiresActive On
ExpiresByType image/gif 86400000
ExpiresByType image/png 86400000
ExpiresByType image/jpg 86400000
ExpiresByType image/jpeg 86400000
ExpiresByType text/html 86400000
ExpiresByType text/javascript 86400000
ExpiresByType text/plain 86400000
Run Code Online (Sandbox Code Playgroud)
您可以使用.htaccess来缓存文件。
#cache html and htm files for one day
<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>
#cache css, javascript and text files for one week
<FilesMatch ".(js|css|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>
#cache flash and images for one month
<FilesMatch ".(flv|swf|ico|gif|jpg|jpeg|png)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>
#disable cache for script files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14671 次 |
最近记录: |