缓存图片,php,js和html [英] Cache for images, php, js, and html

查看:92
本文介绍了缓存图片,php,js和html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想缓存所有的文件,但我无法弄清楚如何让它正常工作,以便测试通过。我目前有

 < meta http-equiv =Cache-Controlcontent =private/> 
< meta http-equiv =Expirescontent =86400000/>
< meta http-equiv =Cache-Controlcontent =max-age = 86400000/>

我添加的最后一行是为了测试是否过期和max-age会有帮助(它没有' t)



我使用 http://www.webpagetest。 org / https://developers.google.com/pagespeed/# ,和 http://gtmetrix.com/



任何人都可以简单告诉我如何确保所有内容都是私密缓存的?我检查了一堆其他页面,但没有人提供合法的HTML代码。请列出实际的代码不只是告诉我使用缓存控制和过期,并像我见过的每个其他网站使用。我真的需要示例代码才能理解。感谢您提前提供任何帮助。我也使用PHP,所以如果在header()中执行它,那也可以。

非常感谢你

编辑:我也尝试使用.htaccess为了做到这一点,但没有奏效。我不知道这是否是我的服务器的设置或什么,但它没有改变任何与测试。

解决方案

在HTML文档中指定过期时间时,它仅适用于实际文档。



假设您有一个带有 mod_expires 已启用,您可以创建一个名为 .htaccess 的文件并包含以下内容:

  ExpiresActive On 
ExpiresByType image / gif 86400000
ExpiresByType image / png 86400000
ExpiresByType image / jpg 86400000
ExpiresByType image / jpeg 86400000
ExpiresByType text / html 86400000
ExpiresByType text / javascript 86400000
ExpiresByType text / plain 86400000


I want to cache all of my files but I can't figure out how to get it to work so that the tests approve. I have currently

<meta http-equiv="Cache-Control" content="private" />
<meta http-equiv="Expires" content="86400000" />
<meta http-equiv="Cache-Control" content="max-age=86400000" />

The last line I added just to test if having expires and max-age will help (it doesn't)

I was using http://www.webpagetest.org/, https://developers.google.com/pagespeed/#, and http://gtmetrix.com/

can anyone tell me simply how to make sure everything is cached privately? I have checked a bunch of other pages but no one gives legit HTML code. Please list actual code don't just tell me to use Cache-Control and expires and that like every other website I have seen uses. I really need example code in order to understand. Thank you for any help in advance. I am also using PHP so if doing it in a header() then that would work too.

Thank you very much

edit: I also tried using .htaccess in order to do it but that didn't work. I don't know if it was a setting with my server or what but it didn't change anything with the test.

解决方案

When you specify an expiration time in an HTML document, it only applies to the actual document.

Assuming you have an Apache webserver with mod_expires enabled, you can create a file named .htaccess and include the following

ExpiresActive On
ExpiresByType image/gif       86400000
ExpiresByType image/png       86400000
ExpiresByType image/jpg       86400000
ExpiresByType image/jpeg      86400000
ExpiresByType text/html       86400000
ExpiresByType text/javascript 86400000
ExpiresByType text/plain      86400000

这篇关于缓存图片,php,js和html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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