Shit!我的host到底怎麼了?
背景
那是今年五月的某一天,我的mac在切換系統host後,chrome遲遲不生效,依然訪問的是原來的環境.
開發和測試同學在做專案時,需要經常進行 日常環境 預發環境 線上環境的切換,其實切的就是系統的host.如果瀏覽器總是延遲,或者死活不生效的活,基本上你就在那不停的重新整理重新整理重新整理. 或者重新啟動瀏覽器.心情會很煩躁的有木有.
解決方案
遇到這個問題的時候,一般我們有以下幾個搞法(只針對chrome哈,重啟瀏覽器就不說了,我標籤一般開啟好幾十,輕易不願意重啟的)
第0招: 強清快取思路. ctrl + shift + r 或者 重新整理按鈕 右鍵彈出一下選單.
正常重新載入 Ctrl+R:正常重新載入。
硬性重新載入:Ctrl+Shift+R:淺層次的清除歷史記錄,但不一定快取完全清除。(Ctrl+F5)同理。
清空快取並硬性重新載入:可以深層次的清除所有的快取。(建議用這個)
但其實這種做法對切換host沒實際作用!
第一招: 開啟 chrome://net-internals/#dns 頁面, 點選 Clear host cache. 一般來講, 有些同學使用這招可以解決host切換的不生效問題了.但是我的chrome使用此招還是無果.
Click on the button to Clear the host resolver cache entries. You would find that the entries in the list would be immediately cleared.By clearing the host resolver cache, you can force Google Chrome to resolve the domains again.
第二招: 開啟 chrome://net-internals/#sockets 頁面, 點選 Flush socket pools. 這招非常狠.終極殺手!絕對解決問題.
終極工具
零: 開啟 https://zoom.alibaba-inc.com/ 安裝ZOOM外掛.
一. 在頁面右鍵選單上會發現[徹底清host快取]的工具, 當然我還做了放置http強制跳轉https
二. 點選[徹底清host快取]選單,彈出提示,讓你去開啟一個許可權. 點選[前往設定]哈.開啟許可權後,瀏覽器會重啟以啟用新的配置.
三. 瀏覽器重啟後,以後需要清dns,右鍵點選[徹底清host快取]後,就ok了.成功後,會給你一個提示
這個提示裡面,有個貼心的小功能,發現沒.
漲點姿勢
DNS快取
感覺下面這段英語描述其實很簡單易懂的,所以我就不放中文了.
A DNS cache (sometimes called a DNS resolver cache) is a temporary database, maintained by a computer`s operating system, that contains records of all the recent visits and attempted visits to websites and other internet domains.
In other words, a DNS cache is just a memory of recent DNS lookups that your computer can quickly refer to when it`s trying to figure out how to load a website.
Most people only hear the phrase “DNS cache” when it refers to flushing/clearing the DNS cache in order to help fix an internet connectivity issue. There`s more on that at the bottom of this page.
為什麼要設定DNS 本地快取?
domain –> [DNS server] –> IP
Even though there are tons of public DNS servers your network can use to try to speed up the conversion/resolution process, it`s still quicker to have a local copy of the map list, which is where DNS caches come into play.
How a DNS Cache Works
Before a browser issues its requests to the outside network, the computer intercepts each one and looks up the domain name in the DNS cache database. The database contains a list of all recently accessed domain names and the addresses that DNS calculated for them the first time a request was made.
Chrome 監聽host變動
Note that Chrome now monitors the hosts file and autoclears the dnscache whenever there are any changes to the hosts file. —You can easily test if that works on your system by adding a blank line after your hosts file, and the list at chrome://net-internals/#dns will be autoupdated.— Windows` dnscache service will also (at least on win 8.1) monitor the hosts file for changes, so after you have updated your hosts file, simply clicking on the button “Flush socket pools” will work. Nothing else is needed.
僅僅清DNS Cache為何還不足夠?
Chrome使用DNS cache和Socket Pool來加速訪問.其實Chrome的DNS cache會在切換hosts檔案之後會自動清理,但是Socket Pool不會.(Chrome can`t use the correct hosts after modifying the hosts file because of Chrome using socket pools.)
Chrome maintains long connections in the connection pool to speed up. When Chrome finds that a request can reuse a connection in the connection pool, it won`t go through the DNS again, thus, we always perceive that Chrome won`t respond to a hosts change immediately.
為什麼我要做這個外掛
Chrome has provided an interface for flushing the connection pool in the chrome://net-internals/#sockets tab, but I think it`s annoying that I have to go to the tab first, and click so a small button with a trackpad.
I found that when clicking the button of flush socket pool, Chrome executes two key JavaScript methods.
g_browser.sendFlushSocketPools();
g_browser.checkForUpdatedInfo(false);
在chrome://* 頁面下,可以發現 window下有個g_browser的物件,其中包含了很多方法.
根據這些搜尋chrome的原始碼,找到了源頭: https://searchcode.com/codesearch/view/86220162/. g_browser 的一堆方法都在這個BrowserBridge類裡面.
每次都開啟chrome://net-internals/#sockets頁面去點選flush按鈕是很煩的.於是我在想, 通過chrome外掛自動開啟這個頁面,然後自動執行 g_browser.sendFlushSocketPools() 豈不是很完美?!
qutos
相關文章
- MVC、MVP、MVVM,我到底該怎麼選?MVCMVPMVVM
- 我到底是怎麼被"炸房掛"轟炸掉線的?
- 天啦,從Mongo到ClickHouse我到底經歷了什麼?Go
- 點開通知 怎麼花屏了。。嚇死我了?
- 從500瘋漲到1200!《健身環》到底怎麼了?
- HTTPS 到底加密了什麼?HTTP加密
- 營收、淨利雙降,蘇泊爾到底怎麼了?營收
- HashMap到底是怎麼put的?HashMap
- “我怎麼就被一張照片出賣了?”
- Spring Cloud中五花八門的分散式元件我到底該怎麼學SpringCloud分散式元件
- 銀行科技到底怎麼樣?我曾經的四年告訴你 !
- 不要再問我Java程式是怎麼執行的了!Java
- 誒,我的動態資料來源怎麼失效了
- vue $set到底幹了什麼Vue
- GoDaddy雲伺服器 | 到底是什麼讓我選擇了它?Go伺服器
- 一份來自大牛的招聘感悟: iOS開發人群到底怎麼了?iOS
- 一封來自大牛的招聘感悟: iOS開發人群到底怎麼了?iOS
- 到底為什麼我們需要 Clickhouse?
- Webpack 中的 sideEffects 到底該怎麼用?WebIDE
- 怎麼了?我就磕上安卓了!沒有男朋友我也要做安卓安卓
- PS4獨佔連續跳槽,獨佔政策到底怎麼了?
- The truth is, shit that is cosmetic is sold by 2K
- 我的電腦圖示不見了怎麼恢復?我的電腦圖示不見了的恢復方法
- RabbitMQ和Kafka到底怎麼選?MQKafka
- 我們常聽到的WAL到底是什麼
- CPU:網路卡老哥,你到底怎麼工作的?
- Host是什麼?如何設定host檔案?
- 《完蛋!我被美女包圍了!》是怎麼做好選擇題的?
- [譯] 我最終是怎麼玩轉了 Vue 的作用域插槽Vue
- 麻了, 接私活被抓了,我說他最近怎麼盒飯都吃35的了
- .NET程式崩潰了怎麼抓 Dump ? 我總結了三種方案
- Promise到底解決了什麼問題?Promise
- new操作符到底幹了什麼?
- 頑皮狗到底做錯了什麼?
- new操作符到底幹了什麼
- 模型中到底什麼決定了效果模型
- 我在家門口散步了7公里,就為了搞清楚“城市智慧體”到底是什麼智慧體
- 當初,我怎麼會頭腦發熱選了Python!Java VS Python怎麼選?PythonJava