什么是浏览器缓存?它从网页数据中存储什么? [英] What Is A Browser Cache? What does it store from a webpage data?

查看:74
本文介绍了什么是浏览器缓存?它从网页数据中存储什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我遇到网站问题时,我会听到的第一个建议是尝试清除浏览器缓存"以及并删除Cookie".那么这个浏览器缓存是什么?它存储什么,有什么用?

我已经用谷歌搜索了.但没有找到正确的答案.如果有人对此提供帮助,我表示感谢.

解决方案

浏览器缓存缓存"(例如保留本地副本)从互联网下载的数据.下次您的浏览器需要相同的数据时,可以从缓存中快速获取数据,而不是通过Internet下载(慢速)

问题在于数据可能很旧.例如,假设浏览器今天缓存了www.nytimes.com,而24小时后您又访问了www.nytimes.com.如果浏览器加载了缓存的数据,那将是旧消息.

因此,有.

Whenever I have an issue with a website, one of the first suggestions I will hear is "try to clear your browser cache" along with "and delete your cookies". So what is this browser cache? What does it store and what is it good for?

I have googled. but didn't find the proper answer.I appreciate if anyone help on this.

解决方案

A browser cache "caches" (as in keeps local copies) of data downloaded from the internet. The next time your browser needs the same data it can get it from the cache (fast) instead of downloading it over the internet (slow)

The problem is that data can be old. For example imagine the browser cached www.nytimes.com today and 24hrs later you visited www.nytimes.com again. If the browser loaded the cached data it would be old news.

So there are headers (metadata) that the servers send to browser telling them how long they should cache something (if at all).

The data the browser generally caches are "requests" which. In other words if your browser asks for "http://foo.com/bar.html" the first time the browser will "request" that "foo.com" send it "bar.html". If the headers from "foo.com" are set a certain way the browser will the save a local copy of "bar.html". If you request the same thing again the browser may load "bar.html" from it's cache. I say "may" because it depends on the headers sent from the server. The server can say how long (say 10 minutes, 10 hours, 10 days, etc..) or it can say "don't cache this at all, always download the newest version".

If you go to your browser's dev tools (chrome shown below) and look at the network tab (not sure what it's called in other browsers). Load the page again and you can see all the requests. You'll also notice which ones were loaded from the cache

If you click on a request you can see the metadata from both the browser (request headers) and the server (response headers)

The reason clearing the cache often fixes things is if for some reason the server (a bug?) said it was ok to cache or used the cached version but the data on the server has actually been updated. The browser, doing what the server told it to do, is using its copy from the cache, not the newer version which is actually needed. There might also from time to time be bugs in the browser itself related to caching.

When everything is working correctly it's great but if one thing or another is mis-configured or sending the wrong headers then the browser can end up loading old data from the cache instead of downloading the newest data. Clearing your cache effectively forces the browser to download the data again.

You can find out the details of what the various headers do here.

这篇关于什么是浏览器缓存?它从网页数据中存储什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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