前阵子解决一个问题的时候,差点以为是我们自己在 HTML 代码中输出的一段信息有问题,结果发现,Chrome 的 View Source Code 竟然会重新发送一个请求!
有史以来,所有的浏览器从来没有过这样天才的设计。大家都是老老实实,既然你让我显示源代码,那我就直接给你把正在看的这个页面的源代码显示出来。没有人想过竟然可以重新发起一个请求,去拿“纯洁的”源代码。这是革命性的!Chrome 你做到了!
早在2008年,就已经有人提出这个 bug – View source forces page reload. 中间有人将之标记过 Fixed,但是世界末日快来了,Chrome 的稳定版本已经飚到18了,市场份额已经远超 Firefox 了,实际上这个 bug 仍然存在。我的天啊,究竟是什么样的设计,导致解决这样一个问题这么难?
甚至还曾有开发者认为 View Source 就应该是这样的行为 (链接):
Yes, when you “view source”, you’re really opening a new tab that opens the page
again and displays the source rather than renders the page. Many web pages are
dynamic and modify their HTML content (eg. using JavaScript/XMLHttpRequest) so we
cannot display the current HTML – this is why a new request is made.If you want to view the current state of a dynamic page, you should use the
inspector. “File icon -> Developer -> JavaScript console”I don’t see how this is a security bug or a bug at all – the behavior is by design –
closing as such.
注意里面加粗倾斜的那段话——因为很多网页是动态的,所以无法显示当前的 HTML,所以发送一个新的请求。这逻辑真够奇怪的!你是想“显示当前的 HTML”吗?你发送一个新的请求解决了这个问题吗?没有解决,那你何必要发一个新的请求?这就相当于脱了裤子,屁还是没有放出来。
Leave a Reply