htaccess利用浏览器缓存图像和CSS [英] htaccess leverage browser caching for images and css

查看:96
本文介绍了htaccess利用浏览器缓存图像和CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的网站创建一个htaccess文件,而pageSpeed的见解表明存在图像和一个css文件没有过期。

I am trying to create a htaccess file for my website and the pageSpeed insights has shown that there are images and one css file without expiration.

我不确定从哪里开始或如何做,我从在线教程中获得了这段代码,并且想知道这样做是否足够。

I am not sure where to start with this or how to do it, I have this code from a tutorial online and was wondering if this would be enough to work.

<IfModule mod_expires.c>
ExpiresActive On
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>

还是此代码执行了我需要做的事情?

Or does this code do what I need it to do?

谢谢

推荐答案

尝试类似

<IfModule mod_expires.c> 
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 86400 seconds"
  ExpiresByType application/x-javascript "access plus 86400 seconds"
</IfModule>

<FilesMatch "\.(?i:gif|jpe?g|png|ico|css|js|swf)$">

  <IfModule mod_headers.c>
    Header set Cache-Control "max-age=172800, public, must-revalidate"
  </IfModule>

</FilesMatch>

这篇关于htaccess利用浏览器缓存图像和CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆