Harry

Results 3 comments of Harry

使用`document.querySelectorAll`实现如下(包括可能次数一样多的标签) ```javascript function getMostFrequentTag() { const counter = {}; document.querySelectorAll("*").forEach((element) => { counter[element.tagName] = counter[element.tagName] ? counter[element.tagName] + 1 : 1; }); const orderedTags = Object.entries(counter).sort((tag1, tag2) => { if...

使用`Element.children`递归实现如下 ```javascript function getMostFrequentTag() { const counter = {}; const traversalElement = (parent) => { if (parent.tagName !== undefined) { counter[parent.tagName] = counter[parent.tagName] ? counter[parent.tagName] + 1 : 1; }...

今天在看这个问题的时候,发现一个关于强制缓存的意外情况。在刷新页面时,有的浏览器会重新验证缓存资源的新鲜度,有的不会。 假设第一次请求资源的Response Heades包含下列强制缓存信息 ``` Date: Tue, 19 Jan 2021 08:37:05 GMT Expires: Tue, 26 Jan 2021 08:37:05 GMT ``` 在有效期内,按照强制缓存的概念解释,再次请求资源时,不会发送请求,直接返回200。 但是在firefox中(使用版本:84.0.2),Request Headers中包含`If-Modified-Since`头部,所以仍然会发送请求,返回304。 在chrome中(使用版本:87.0.4280.141),不会发送请求,会直接使用缓存的资源,返回200。 在stackoverflow找到了一些关于这个问题的回答https://stackoverflow.com/questions/45829055/why-doesnt-chrome-re-validate-in-memory-cache-when-doing-a-normal-reload/57281076#57281076