客户端浏览器缓存

浏览器本地缓存静态数据

1)使用Firefox浏览器查看缓存
以Firefox浏览器为例,在Firefox地址栏内输入about:cache将显示Firefox浏览器的缓存信息,点击List Cache Entries可以查看详细信息
2)清空firefox本地缓存数据
3)修改Nginx配置文件,定义对静态页面的缓存时间

# vim /usr/local/nginx/conf/nginx.conf

在server里面添加一个location,不要添加在原有的location里面。
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location /status {
stub_status on;
}
location / {
root html;
index index.html index.htm;
}

location ~* \.(jpg|png)$ { #添加这3行,后面括号里是什么jpg之类要看工作时用到的类型
expires 30d; #定义客户端缓存时间为30天
}
}
---------------------------------------------------------------------------------------------
# nginx -s reload
# cp /usr/share/backgrounds/day.jpg /usr/local/nginx/html/ #拷贝一个桌面背景图片
---------------------------------------------------------------------------------------------
4)优化后,真机使用Firefox浏览器访问图片,再次查看缓存信息
然后清除火狐的全部历史记录,然后访问刚才复制的图片
firefox 192.168.4.5/day.jpg
真机在Firefox地址栏内输入about:cache,查看本地缓存数据的位置,查看是否有图片以及过期时间是否正确。


disk
Number of entries: 2 #这是火狐的历史记录信息
Maximum storage size: 358400 KiB
Storage in use: 386 KiB
Storage disk location: /root/.cache/mozilla/firefox/1eewp1tc.default/cache2 #这是它的缓存位置
List Cache Entries #点这个可以看到精确的浏览的历史记录!!!

Key Data size Fetch count Last Modifed Expires Pinning
http://192.168.4.5/day.jpg 392746 bytes 2 2018-11-03 10:44:52 2018-12-03 10:44:51

猜你喜欢

转载自www.cnblogs.com/summer2/p/10787936.html