Live data from Hacker News

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

news.ycombinator.com

41–50 of 97 posts

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

#41
post #27
post #13

Earlier quoted context omitted.

How much memory is saved here? http://www.httparchive.org/interesting.php?a=All&l=Dec%202%2... 52 _kilobytes_ ? Really?

The browser would have to save the source text for EVERY tab it opens, regardless of whether you view source or not. That seems more onerous than making a separate request for the source code every once in a while.

But the amount of memory required for plain text source is very small compared to the memory allocated to render the page.

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

#42
post #32

Earlier quoted context omitted.

Yes, but if you have more than enough memory, then that's no problem. So, the browser should load the HTML page into a part of memory that can be discarded by the OS if the OS needs more memory. Actually I think it is strange that no such memory API exists in Unix. EDIT: Anyway, storing it in the browser's file cache would also do the trick, I suppose :)

Isn't that one of the issues nowadays, that people have the attitude "we have enough memory" and thus don't tend to care about optimizing for memory usage anymore. Your suggested solution, about discarding when memory is needed, solves this problem. But it solves a problem that would be created by needlessly storing a lot more data than needed. So it's a solution to a problem that was not a problem to begin with. But…

So hide it behind a feature flag?

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

#43
post #32

Earlier quoted context omitted.

Yes, but if you have more than enough memory, then that's no problem. So, the browser should load the HTML page into a part of memory that can be discarded by the OS if the OS needs more memory. Actually I think it is strange that no such memory API exists in Unix. EDIT: Anyway, storing it in the browser's file cache would also do the trick, I suppose :)

Isn't that one of the issues nowadays, that people have the attitude "we have enough memory" and thus don't tend to care about optimizing for memory usage anymore. Your suggested solution, about discarding when memory is needed, solves this problem. But it solves a problem that would be created by needlessly storing a lot more data than needed. So it's a solution to a problem that was not a problem to begin with. But…

> "we have enough memory"

Your phone is in disagreement.

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

#44

Earlier quoted context omitted.

Couldn't you reconstruct the source from the internal dom representation anyway?

No. The parser corrects and changes the source to make the DOM. So it is impossible to find errors usually. So things like: the parser will correct, and therefore the DOM will be correct. But what it does to fix this may break your site. I often found the CSS would be screwed up for many reasons (rules don't match DOM structure -- due to bugs all over our codebase)

oh right.

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

#45
I suppose in today's web ecosystem, the initial HTML state of the page is useless in almost all cases after the DOM loads. Rarely will you care about the pre-javascript page, and if you do, you're probably debugging a web site, and the extra load shouldn't matter.

Where it could get interesting though, is if the content changes before you view the source. In that case, you're out of luck I guess.

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

#46
post #32
post #27

Earlier quoted context omitted.

The browser would have to save the source text for EVERY tab it opens, regardless of whether you view source or not. That seems more onerous than making a separate request for the source code every once in a while.

Yes, but if you have more than enough memory, then that's no problem. So, the browser should load the HTML page into a part of memory that can be discarded by the OS if the OS needs more memory. Actually I think it is strange that no such memory API exists in Unix. EDIT: Anyway, storing it in the browser's file cache would also do the trick, I suppose :)

Similar "tab discarding" feature already exists in Chrome, by the way:

https://developers.google.com/web/updates/2015/09/tab-discar...

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

#47
post #27
post #13

Earlier quoted context omitted.

How much memory is saved here? http://www.httparchive.org/interesting.php?a=All&l=Dec%202%2... 52 _kilobytes_ ? Really?

The browser would have to save the source text for EVERY tab it opens, regardless of whether you view source or not. That seems more onerous than making a separate request for the source code every once in a while.

Am I in some parallel universe here ?

We are talking about hundreds of KBs of memory total which is nothing and if it's a worry for mobile devices we have the disk. It's not a feature that demands instant performance.

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

#48
post #15

I seem to recall that it wasn't always the case.

True and I was shocked that the referenced mozilla bug[1] is from 2006. Time really flies because it feels like yesterday I could view source without re-loading it. [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=307089

Sweet memories:

http://imgur.com/a/p02cQ

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

#49
post #27

Earlier quoted context omitted.

The browser would have to save the source text for EVERY tab it opens, regardless of whether you view source or not. That seems more onerous than making a separate request for the source code every once in a while.

Am I in some parallel universe here ? We are talking about hundreds of KBs of memory total which is nothing and if it's a worry for mobile devices we have the disk. It's not a feature that demands instant performance.

> It's not a feature that demands instant performance.

Hence it's acceptable to request the document from the server when opening 'View Source'.

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

#50

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.

Why would you need the original HTML for dev tools to work? Maybe there are ones I've never seen but the ones I use are using the DOM rather than the original HTML string.

I showed a few people who have no idea about programming whatsoever how to hack websites to download .mp4 or .mp3 from source code of the website. How would you show them that using DOM...
Post reply on HN