ELI5: How can multiplayer games send information back and forth to players in split-second combat (including processing time), but it takes 2 seconds to load a basic webpage?

Honestly? Because the average person is willing to wait a few seconds. Back when I learned HTML that was 20 seconds on 28.8K, so you ensured your page loaded in that time period. Here's the basic process for page loading:

  • Send a request to your DNS server for the IP address of the web server
  • Request one or more TCP connections to port 80
  • Receive a 'connected' response
  • Transmit one or more GET requests using the HTTP protocol
  • The webserver either retrieves the file and sends it, or executes the script
  • Most scripts use an SQL database, so this whole process is repeated for the script to communicate with the database
  • Receive a response from the server
  • Parse the HTML received, execute the javascript
  • See which external resources the page requires and repeat this process for each of them

Realistically, that takes less than 100 milliseconds. Modern webpages exploit that speed to do a lot of unnecessary crap. First, webpages now are behemoths, the code is very inefficient, (the Google search page is a notable exception). Second, just about every page is dynamic now. Retrieving an HTML page from disk takes milliseconds, generating a dynamic page depends on the script efficiency & CPU resources available. Most scripts access a database over the internet (or local LAN), which further slows them down.

Then, the average page references Javascript 'libraries' (so dozens/hundreds of KB of code that never gets used), and hoards of files from remote servers. They also set huge cookies that your browser has to transmit with every get request. This page, for example, transmits and receives information from: 3 Reddit domains, Amazon, Imgur, Bitpay, Paypal, and AdZerk. Google hosts an AJAX library that's commonly used, and thus has information on most of the internet browsing you do. It's fairly annoying when you realize that you're waiting just so you can be tracked. That millions of people's browsing habits & cumulative lifetimes of waiting are worth less than an hour of a single developer's time.

/r/explainlikeimfive Thread