HTTP标头过期在Wordpress中实现

时间:2013-04-29 10:43:09

标签: php wordpress http header expires-header

我正在Wordpress中实现HTTP Header expires实现 - 比如说浏览器端缓存用于减少服务器的命中数,以及通过从浏览器而不是服务器加载css / images / js文件来减少加载时间。

以下是我目前在.htaccess中添加的内容

<FilesMatch "\.(js)$">  
FileETag none
ExpiresActive On
ExpiresDefault "access plus 1 month"
</FilesMatch>

使用上面的代码,我可以看到从主题文件夹加载的所有js文件的到期时间设置为一个月,但是来自js文件夹的jQuery文件呢? .htaccess中的上述条目并未针对此目的。我们也能掩盖它们吗?

QQ-任何缓存js / css / images或覆盖其到期时间的方法,让我们设置自己的(更长)时间。

由于

1 个答案:

答案 0 :(得分:0)

尝试以下代码

<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 month"
</FilesMatch>

<IfModule mod_expires.c>
AddType image/x-icon .ico
ExpiresActive on
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css M604800
ExpiresDefault M604800
</IfModule>