javascript - 如何缓存png,ico,jpeg

标签 javascript .htaccess png jpeg ico

如何使用 htaccess 将图像缓存在我的网站上 2 天:

1 x 60 x 60 x 24 x 2 = 172800s

所以我想缓存'png, jpeg, jpg, ico, js'。我怎样才能用 htaccess 做到这一点

最佳答案

您可以使用 mod_expires 模块(基于文件的 MIME 类型):

<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300

# png, jpeg, jpg, ico, js expire after 2 days
ExpiresByType image/gif A172800
ExpiresByType image/png A172800
ExpiresByType image/jpg A172800
ExpiresByType image/x-icon A172800
ExpiresByType application/x-javascript A172800
</ifModule>

或者 mod_headers 模块(基于文件扩展名):

<ifModule mod_headers.c>
ExpiresActive On

# png, jpeg, jpg, ico, js expire after 2 days
<filesMatch ".(gif|png|jpg|jpeg|ico|js)$">
Header set Cache-Control "max-age=172800"
</filesMatch>
</ifModule>

最后一个为您提供了更多选项,例如强制无缓存等。

关于javascript - 如何缓存png,ico,jpeg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23251158/

相关文章:

javascript - 使用 PhantomJS 打开 RequireJS 应用程序

javascript - Thunderbird 撰写发送消息事件不会触发

javascript - facebook 的 all.js 太大了,有替代方案吗

apache - Htaccess 重定向命令不区分大小写

c++ - stb_png_to_mem的参数是什么意思?

javascript - 如何提醒 View 显示数据

Apache Web 服务器不允许我刷新 on/about,但在 localhost 上它工作正常

html - 此 URL 如何响应图像或嵌入该图像的网页?

java - 使用纯 OpenGL 加载 PNG 文件

html - CSS:Internet Explorer(任何版本)中的奇怪平铺错误