Search code examples
texteditorsavetext-editorautosave

Autosave triggering in a text editor application


I need to implement an auto-save function in a text editor web-application to manage automatic save when the user is typing. I don't have specific knowledge about this kind of technology so I wonder how it is handled in a modern web-based text editor, and specially, when the save function is triggered:

  • Is it triggered by the keyboard event itself or by a periodic scan (every 5 seconds for instance) that checks for previous keyboard events?
  • Does it have to be triggered when the user is not typing (after 3 seconds of inactivity for instance) to reduce network traffic?

Any suggestions?

Thanks


Solution

  • For instance, here is described autosave in Wordpress. My opinion is that depends on type of application. The best way to find the best solution is, I guess, that way that you would like to see if you visit some site.

    So, if you put somewhere "Save" button, then I think that you really don't need to trigger it every few seconds, but every few minutes (like Wordpress do).

    Since you will listen to events by client-side language (JavaScript probably), you don't need to worry much about performance - just listen every 10 seconds if you want and check if requirements are met for autosaving. If they are, you save it in some database with some AJAX magic.

    If I were you (or, if I am The User of your site), I would like to start listening to events on first keyUp. When I entered first letter, then, JS would store in DB via AJAX every 1 min OR every 500-1000 characters entered, whatever is first met. I guess it would be great to take in account that someone types faster, someone slower. That's why I would check both number of chars entered as well as time.

    That's my opinion. ( eventually sorry for grammar, free for editing :D )

    EDIT: Also, if site is yours and you expect some big traffic and a lot of users, you can dynamically see how system works and accordingly set your variables (longer/shorter time/chars)