如何使用Cache Control和ETag设置http标头

时间:2014-11-14 07:09:11

标签: caching joomla cache-control pagespeed etag

我想在谷歌建议的joomla网站中使用Cache Control和ETag。但不知道该怎么做。我用Google搜索了很多,但找不到任何可疑的例子。

任何人都可以告诉我该怎么做.. ??

对于缓存控制,我找到了this示例,但这是完整的语法.. ??以及将其放在<head>文件的index.php标记中的位置??

另请告诉我ETag的语法以及编写它的地方。

1 个答案:

答案 0 :(得分:5)

您可以在网站的根目录中使用.htaccess文件。您会发现有很多不同的细节,这里是http://www.siteground.com/tutorials/joomla/joomla-speed.htm#htaccess的全面变体。

使用文本编辑器,将以下内容添加到.htaccess文件

编辑如果您的目标是专门用于提高您的YSlow分数,并且您没有将这些代码用于任何其他目的,那么最好将以下ETag设置为:

FileETag none 

来源:https://developer.yahoo.com/performance/rules.html#etags

########## Begin - ETag Optimization
## This rule will create an ETag for files based only on the modification
## timestamp and their size. 
## Note: It may cause problems on your server and you may need to remove it  
## Note: See comments above about why you might want to set the following to FileETag none 
FileETag MTime Size
# AddOutputFilterByType is now deprecated by Apache. Use mod_filter in the future.
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript
# Enable expiration control
ExpiresActive On
# Default expiration: 1 hour after request
ExpiresDefault "now plus 1 hour"
# CSS and JS expiration: 1 week after request
ExpiresByType text/css "now plus 1 week"
ExpiresByType application/javascript "now plus 1 week"
ExpiresByType application/x-javascript "now plus 1 week"

# Image files expiration: 1 month after request
ExpiresByType image/bmp "now plus 1 month"
ExpiresByType image/gif "now plus 1 month"
ExpiresByType image/jpeg "now plus 1 month"
ExpiresByType image/jp2 "now plus 1 month"
ExpiresByType image/pipeg "now plus 1 month"
ExpiresByType image/png "now plus 1 month"
ExpiresByType image/svg+xml "now plus 1 month"
ExpiresByType image/tiff "now plus 1 month"
ExpiresByType image/vnd.microsoft.icon "now plus 1 month"
ExpiresByType image/x-icon "now plus 1 month"
ExpiresByType image/ico "now plus 1 month"
ExpiresByType image/icon "now plus 1 month"
ExpiresByType text/ico "now plus 1 month"
ExpiresByType application/ico "now plus 1 month"
ExpiresByType image/vnd.wap.wbmp "now plus 1 month"
ExpiresByType application/vnd.wap.wbxml "now plus 1 month"

ExpiresByType application/smil "now plus 1 month"
# Audio files expiration: 1 month after request
ExpiresByType audio/basic "now plus 1 month"
ExpiresByType audio/mid "now plus 1 month"
ExpiresByType audio/midi "now plus 1 month"
ExpiresByType audio/mpeg "now plus 1 month"
ExpiresByType audio/x-aiff "now plus 1 month"
ExpiresByType audio/x-mpegurl "now plus 1 month"
ExpiresByType audio/x-pn-realaudio "now plus 1 month"
ExpiresByType audio/x-wav "now plus 1 month"

# Movie files expiration: 1 month after request
ExpiresByType application/x-shockwave-flash "now plus 1 month"
ExpiresByType x-world/x-vrml "now plus 1 month"
ExpiresByType video/x-msvideo "now plus 1 month"
ExpiresByType video/mpeg "now plus 1 month"
ExpiresByType video/mp4 "now plus 1 month"
ExpiresByType video/quicktime "now plus 1 month"
ExpiresByType video/x-la-asf "now plus 1 month"
ExpiresByType video/x-ms-asf "now plus 1 month"

或者,你会发现很多扩展,它们将在JED中做类似的事情 http://extensions.joomla.org/extensions/core-enhancements/performance/cache

祝你好运!