如何为WordPress和Typecho设置静态资源缓存

默认分类 未结 1 1229
___平常心
___平常心 2023-03-17 21:11
1条回答
  • 2023-03-17 21:48

    在HTTP标头中为静态资源设置过期日期或最长存在时间,可指示浏览器从本地磁盘中加载以前下载的资源,而不是通过网络加载。这样, 网站加载速度会更快.下面的代码都需要放到.htaccess中才能生效. 推荐设置过期时间为一个月, 即: max-age=2592000.####通过FilesMatch设置Header set Cache-Control "max-age=2592000"####通过mod_expires.c设置ExpiresActive On ExpiresDefault "access plus 1 months" ExpiresByType text/html "access plus 1 months" ExpiresByType image/gif "access plus 1 months" ExpiresByType image/jpeg "access plus 2 months" ExpiresByType application/x-shockwave-flash "access plus 2 months" ExpiresByType application/x-javascript "access plus 2 months"如需针对具体的资源类型需要这样:ExpiresByType image/gif "access plus 5 hours 3 minutes"更多规则参考Apache Module mod_expires.参考来源:Cache Control with htaccess FILES MATCHApache里配置 mod_expires 和 mod_headers 以支持CACHETags: wordpress静态资源缓存, typecho静态资源缓存, wordpress浏览器缓存, typecho浏览器缓存, 静态资源缓存, 浏览器缓存,wordpress cache expire, typecho cache expire

    在http标头中为静态资源设置过期日期或最长存在时间,可指示浏览器从本地磁盘中加载以前下载的资源,而不是通过网络加载。这样, 网站加载速度会更快. 下面的代码都需要放到.htaccess中才能生效. 推荐设置过期时间为一个月, 即: max-age=2592000. ####通过filesmatch设置 header set cache-control "max-age=2592000" ####通过mod_expires.c设置 expiresactive on expiresdefault "access plus 1 months" expiresbytype text/html "access plus 1 months" expiresbytype image/gif "access plus 1 months" expiresbytype image/jpeg "access plus 2 months" expiresbytype application/x-shockwave-flash "access plus 2 months" expiresbytype application/x-javascript "access plus 2 months" 如需针对具体的资源类型需要这样: expiresbytype image/gif "access plus 5 hours 3 minutes" 更多规则参考apache module mod_expires. 参考来源: cache control with htaccess files match apache里配置 mod_expires 和 mod_headers 以支持cache tags: wordpress静态资源缓存, typecho静态资源缓存, wordpress浏览器缓存, typecho浏览器缓存, 静态资源缓存, 浏览器缓存,wordpress cache expire, typecho cache expire

    0 讨论(0)
提交回复