浏览器缓存问题总结 红太狼 2022-04-23 00:54 193阅读 0赞 一种修改浏览器缓存的方法:修改服务器配置 1,原理 [参考文章][Link 1] 2,Apache配置 开启expire 打开**apache**安装目录,找到**conf**目录,打开**httpd.conf** 文件。 **ctrl+f** 查找 **LoadModule expires\_module modules/mod\_expires.so** 去掉前面 **\#**号,去掉注释 配置**cache-control,在文本最后添加** <IfModule expires_module> #打开缓存 ExpiresActive on #css文件缓存一个小时,单位为s ExpiresByType text/css A3600 #js文件缓存1个小时 ExpiresByType application/x-javascript A3600 ExpiresByType application/javascript A3600 #html文件缓存83天 ExpiresByType text/html A7200000 #图片文件缓存83天 ExpiresByType image/jpeg A7200000 ExpiresByType image/gif A7200000 ExpiresByType image/png A7200000 ExpiresByType image/x-icon A7200000 </IfModule> 3,Nginx配置 配置html/htm缓存一个小时 location / { access_log /data/nginx/log/xxx.log api; root /home/www/html; if ($request_filename ~ .*\.(htm|html)$) { add_header Cache-Control max-age=3600; } } 当配置完成之后,在控制台network中会看到如下内容: ![设置cache-control之后][cache-control] 这样当你在服务器修改文件之后,当你再次打开该网站的时候,如果距离上次打开超过了设置max-age,则重新加载状态为200;当时间小于max-age 时则从缓存中读取状态为304; 之前解决缓存问题都是从前端页面出发,很费时间,有时没有效果。目前感觉配置服务器这个方法解决缓存问题很彻底。 参考文章: [https://blog.csdn.net/canot/article/details/76359917][https_blog.csdn.net_canot_article_details_76359917] [Link 1]: https://www.cnblogs.com/chenqf/p/6386163.html [cache-control]: /images/20220323/775a24fe852445218b196e9fc7a4fcfc.png [https_blog.csdn.net_canot_article_details_76359917]: https://blog.csdn.net/canot/article/details/76359917
还没有评论,来说两句吧...