Live data from Hacker News

Ask HN: Why does 'View Source' issue a new HTTP request?

news.ycombinator.com

1–10 of 97 posts

Ask HN: Why does 'View Source' issue a new HTTP request?

#1
I've noticed that both Firefox and Chrome issue a new HTTP request when you view the source for a web page that you've already loaded. It's particularly annoying when the page itself is slow to load or if it won't load at all.

Why is that? Wouldn't they have the existing source for the originally received page cached already? Is it based on Cache-Control headers?

This has been on my mind for a while (usually comes up when looking at what's behind slow web apps) and came up again with Piwik on the front page[1]. Their website was semi-down (HN hug of death) but eventually loaded. I wanted to see what their GA equivalent tracking code looks like but the page failed to load as rather than showing the cached copy, it tried to fetch a new one.

[1]: https://news.ycombinator.com/item?id=13210195

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#2
I usually have Fiddler running constantly in the background.

If a page is slow to load and I want to see the HTML, I would find the actual HTTP request in fiddler and grab the HTML that way.

Alternatively, the element inspector doesn't re-issue the request, but it will show the compiled HTML, so after DOM augmentation etc

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#6
post #3

I'm not exactly sure why browsers do that, but I suspect that's due to caching. However, I would suggest that you use "Inspect element" and open up dev tools - this way you will see DOM exactly as it is rendered.

Often the dom has been changed, and you want to know what the server actually sent

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#7
It's a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=307089

Or, it's a memory saving feature. To implement "View source from cache" requires keeping around the raw page HTML, which you might not otherwise need after parsing - except you probably will for all the developer tools to work, so this probably should just be considered bug.

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#8
post #5

I think it may just be because in both cases it opens in a new tab with the view-source modifier, it treats it like you just opened a copy of the page in a new tab? I believe if you open the inspector instead it does not issue a new request.

> I think it may just be because in both cases it opens in a new tab with the view-source modifier, it treats it like you just opened a copy of the page in a new tab?

Interesting. I never payed attention to the resource prefix. Are those standardized at all? Both Firefox and Chrome use the same "view-source:" prefix.

> I believe if you open the inspector instead it does not issue a new request.

The inspector shows the current DOM, not the original loaded HTML, which could be different. It's probably "good enough" as in most cases the original HTML would be the simpler one (say a single div for a single page app) and the live DOM would show what look like right now.

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#9
post #6
post #3

I'm not exactly sure why browsers do that, but I suspect that's due to caching. However, I would suggest that you use "Inspect element" and open up dev tools - this way you will see DOM exactly as it is rendered.

Often the dom has been changed, and you want to know what the server actually sent

You can still do that with the inspect menu; if you look at the network history in Chrome, you can see the headers sent, the headers received and the body sent / received.

Re: Ask HN: Why does 'View Source' issue a new HTTP request?

#10

It's a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=307089 Or, it's a memory saving feature. To implement "View source from cache" requires keeping around the raw page HTML, which you might not otherwise need after parsing - except you probably will for all the developer tools to work, so this probably should just be considered bug.

Wow first raised in 2005. Nice!
Post reply on HN