Welcome, Guest. Please login or register.

Author Topic: How does a web browser work?  (Read 1714 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
How does a web browser work?
« on: January 21, 2007, 12:48:30 AM »
Hi,
I'm not much of a programmer and these are probably going to be some really dumb sounding questions, but here I go anyway...

How does a browser basically work?

I'm guessing that it must interpret html and scripts on the fly?

But how does it decide what gets done first? for example if images, html and scripts are contained on a web page which items are actions taken on first?

On an Amiga hows does data get sent back and forth between the  browser and the TCP/IP stack software?

Thank you in advance for your help,
AmigaEd
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - PrĂ­stino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: How does a web browser work?
« Reply #1 on: January 21, 2007, 01:00:58 AM »
Well, since this is quote generic query, I won't go into details.
Quote
How does a browser basically work?

By fetching and parsing the webpages, and then displaying (rendering) them to user to see. User can give input and take actions, and these will lead to other pages being displayed, or the content of the page being updated.

See Wikipedia: Web browser for more.

Quote
But how does it decide what gets done first? for example if images, html and scripts are contained on a web page which items are actions taken on first?

Whichever happens to come first (HTML is very structured markup language, elements are in certain ordered structure). Some elements might have higher priority than others, however. Some parts might depend on others to be 'resolved' first. Also, smart renderers first get enough information about all elements to know their sizes (if possible), and then figure out the layouting needed. After that the elements are rendered. If no size information is available, the page will be jumpy while loading (elements are 'dancing' as they're loaded and the layouting changes realtime).

Needless to say this is huge over-simplification. If you really want to know how simple web page renderer works, see aweb source code.

Quote
On an Amiga hows does data get sent back and forth between the browser and the TCP/IP stack software?

bsdsocket.library - This is a dynamically created library that TCP/IP stacks create to memory. It has all the APIs needed to talk to the network stack.
 

Offline Waccoon

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1057
    • Show only replies by Waccoon
Re: How does a web browser work?
« Reply #2 on: January 21, 2007, 01:58:45 AM »
In general, how a browser interprets code varies.  The whole point of HTML (at least, as it is applied today) is to simply describe content, rather than to present it, so techniques may be wildly different.  Almost all browsers these days dynamicly render things over and over as more information is downloaded.  Further refreshes may occur if Javascript, DOM, or other dynamic HTML techniques are used.

All browsers have to parse the HTML into a tree, which is constantly expanded and updated as code is parsed.  The code is "upscaled" into a more modern or otherwise fundamental languages, such as SGML or XML.  Hardly any web browsers use HTML properties internally.  Various proprietary techniques are used to fix broken code.  I believe most tag attributes are parsed right-to-left.

Rendering depends on the engine.  They usually start with text, then tables and sections, CSS (if supported), and then objects, such as images.  Everything has a priority set to it -- some browsers respect the priorities set by the W3C, some don't.  Basicly, the stuff that's easiest to draw will be rendered first.  This improves resposiveness, at the expense of having to draw the page more often.

Older browsers used to start drawing stuff right away in chunks, usually separated with
,

, and header tags.  That allowed people to start reading (sometimes ugly) content while they were waiting for the rest of the page to load.

These days, such rendering techniques cause all kinds of visual havoc, such as the infamous Flash of Unstyled Content, and widths and other layout properties are rarely described in the HTML source, so browsers tend to download more content before rendering a page.

 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: How does a web browser work?
« Reply #3 on: January 21, 2007, 02:23:41 AM »
Maybe as a conclusion it should be pointed out that something like rendering most web pages correctly is probably one of the most difficult tasks programmer (or rather army of programmers) can tackle. It is a very hard and complex task, and depends on hundreds of smaller components to come together.
 

Offline Waccoon

  • Hero Member
  • *****
  • Join Date: Apr 2002
  • Posts: 1057
    • Show only replies by Waccoon
Re: How does a web browser work?
« Reply #4 on: January 22, 2007, 05:16:01 AM »
Only if the person who writes the code doesn't do it properly.  You know, graceful degredation, and all that.

The problem is that HTML isn't a standard.  It was supposed to be an easy language based on SGML, but broke a huge number of SGML rules, such as the lovely concept that paragraph tags did not have to be closed, which is completely illegal in SGML.  HTML was so severely crippled early on, but to appease the masses of people who already used it, the standard was changed again and again in an attempt to "fix" it.  Standards aren't supposed to change in ways that break backwards compatibility.  Major syntax changes tend to do that.

Parsing and rendering HTML is actually very easy.  Basic, embedded web browsers may be as small as 300K.  But, due to the inconsitency (not all of which is Netscape and Microsoft's fault), web browsers end up being these 10-20MB behemoths.  Today, for example, it is illegal in HTML 4.01 to terminate META tags.  That's the complete opposite of what's supposed to happen.

That's the problem with a lot of languages.  They get thrown together in a quick-and-dirty fashion, and if they start to become popular, people would rather maintain compatibility with horribly broken code, than make a proper standard.  That results in a lot of bloat in the applications that have to parse these languages.
 

Offline AmigaEdTopic starter

  • His Dudeness, El Duderino
  • Hero Member
  • *****
  • Join Date: Jan 2005
  • Posts: 512
    • Show only replies by AmigaEd
Re: How does a web browser work?
« Reply #5 on: January 23, 2007, 02:10:21 AM »
Thank you guy's for all of the information...

Some of this is actually starting to make sense to me. I did look at the Aweb source code (much of which was beyond my current understanding) but I definitely could start to get a feel for the complexity of the browser. I could also see that parsing could quickly become overwhelming with all of the possible languages, scripts, etc. that could be thrown at the browser.

I guess that I should have become interested in this kind of stuff back in 1994 or so.

Things seemed less complicated back then. :eek:

Regards,
AmigaEd
"Pretty soon they will have numbers tattooed on our foreheads." - Jay Miner 1990

La Familia...
A1K - La Primera Dama -1987
A1K - La Princesa- January 2005
A2K - La Reina - February 2005
A2K - Doomy - March 2005
A500 - El Gran Jugador - April 2005
A1200 - La Hermosa Vista - May 2005
A2KHD - El Duro Grande - May 2005
A600 - PrĂ­stino - May 2005
A1200 - El Trueno Grande - July 2005
CDTV - El Misterioso - August 2005
C64 - El Gran Lebows