Live data from Hacker News

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

news.ycombinator.com

71–80 of 97 posts

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

#71

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.

You don't typically.

One case where you would View Source in addition to using Dev Tools is debugging how the browser is massaging your source HTML into the DOM, for example by inserting missing elements. Validating your HTML mostly addresses this (I'm actually not sure about the example, I would hope the validator at least issues a warning), but isn't something you necessarily want or can do with, for example, user-uploaded HTML snippets.

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

#72
post #64
post #51

Earlier quoted context omitted.

No, because when you want to view the source you mean to view the source of this very document, not the source you'd get by asking to reload the page, it is often different.

If you want to see the page as it's currently being rendered, looking in the developer tools seems more relevant anyway.

If they wanted that, they'd have looked at the developer tools to begin with.

Many of you folks are completely missing the point. The world wide web took off in large part because it was incredibly easy to learn HTML, because with every webpage if one wanted to know how it worked one could just look at the source code.

How the page is currently being rendered, what state the DOM might be in... These things do not matter to someone trying to view the source HTML for a page. They're looking to learn about the HTML. They're not goimg to get that by viewing pre-digested DOM information.

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

#73

Earlier quoted context omitted.

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'.

No it's not, and it's particularly inappropriate for any document being viewed as a result of a POST request.

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

#74
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 :)

You are talking about an OS-provided cache for the browser to store it's own cache in? There's little sense in that.

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

#75

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.

> requires keeping around the raw page HTML

Isn't it already in the browser's cache in that state anyway?

And if the cache is small, the preservation doesn't even have to be "for all tabs," if the last few pages can be retrieved from the cache nobody would complain that the older ones behave as they behave now -- you typically don't do "I wonder what was the source of the page from yesterday" in this old tab, but even if you do, you wouldn't be surprised that the source of yesterday does have to be requested again. So I imagine the fix as just "if in the cache, get it from there, else request."

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

#78
post #52

Earlier quoted context omitted.

My phone has a quite insane 3 GB of RAM.

My phone also has the insane 3GB of RAM, but last week Chrome killed Spotify and vice versa (music stopped playing) as soon as I switched apps. Sadly 3GB is not enough for Android and todays apps.

[deleted]

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

#79
post #52

Earlier quoted context omitted.

> "we have enough memory" Your phone is in disagreement.

My phone has a quite insane 3 GB of RAM.

The most common $150 phone from last year only has 1GB, half of which is reserved for the OS.

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

#80
post #50

Earlier quoted context omitted.

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...

ctrl+shift+i, ctrl+f "mp4"
Post reply on HN