Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Google Docs autosave work?

Okay, I know it sounds generic. But I mean on an AJAX level. I've tried using Firebug to track the NET connections and posts and it's a mystery. Does anyone know how they do the instant autosave constantly without DESTROYING the network / browser?

like image 315
Shamoon Avatar asked May 25 '11 14:05

Shamoon


People also ask

Does Google Docs automatically save work?

When you're online, Google automatically saves your changes as you type. You don't need a save button. If you aren't connected to the Internet, you can set up offline access to save your changes.

How does Google autosave work?

When you fill out a Google Form in your Google account, your progress is automatically saved as a draft for 30 days. This means if you can't complete a form or need to switch devices, you don't have to start over the next time you open the form. Important: If you're offline, autosave doesn't work.

How often does Google Docs automatically save?

Just like Google Slides and Docs, Google Sheets saves changes to your document in real-time. This means that every change to the file (exiting a cell, adding value, changing the format, inserting functions) will be saved.

How do you autosave on Google Docs?

Go to File > Options > Save, and select or clear AutoSave OneDrive and SharePoint Online files by default on Word.


1 Answers

My guess (and this is only a guess) is that google uses a PUSH service. This seems like the most viable option given their chat client (which is also integrated within the window) also uses this to delivery "real time" messages with minimal latency.

I'm betting they have a whole setup that manages everything connection related and send flags to trigger specific elements. You won't see connection trigers because the initial page visit establishes the connection then just hangs on the entire duration you have the page open. e.g.

  1. You visit the page
    • The browser established a connection to [example]api.docs.google.com[/example] and remains open
  2. The client-side code then sends various commands and receives an assortment of responses.
  3. These commands are sent back and forth until you either:
    • Lose the connection (timeout, etc.) in which case it's re-established
    • The browser window is closed

Example of, how I see, a typical communication:

SERVER:                              CLIENT:
-------                              -------
                                     DOC_FETCH mydocument.doc
DOC_CONTENT mydocument.doc 15616 ...      
                                     DOC_AUTOSAVE mydocument.doc 24335 ...
                                     IM collaboratorName Hi Joe!
IM_OK collaboratorName OK
AUTOSAVE_OK mydocument.doc OK

Where the DOC_FETCH command is saying I want the data. The server replies with the corresponding DOC_CONTENT <docname> <length> <contents>. Then the client triggers DOC_AUTOSAVE <docname> <length> <content>. Given the number of potential simultaneous requests, I would bet they keep the "context" in the requests/responses so after something is sent it can be matched up. In this example, it knows the IM_OK matches the second request (IM), and the AUTOSAVE_OK matches the first request (AUTOSAVE)--Something like how AOL's IM protocol works.

Again, this is only a guess.

--

To prove this, use something like ethereal and see if you can see the information transferring in the background.

like image 170
Brad Christie Avatar answered Nov 04 '22 15:11

Brad Christie