2

Suppose there is a site (a javascript app) which users regularly use and they request the ability to save their state on the site, so they can continue from where they left off.

The site has no database backend, it's all a one page javascript app which has a pretty complicated state, so simply generating an url is not an option, because the state can be several kilobytes, so it's too big for an url.

Cookies are also not an option both because of the size and because I want the state to be portable, so when the user saves it he can use it to continue on an other machine too.

Since I don't want to complicate the site with a database backend and authentication I thought the site's state could be generated as a text which the user can copy and later can paste this text config to a text field which can be parsed from javascript to restore app state.

It can work, though it's somewhat cumbersome for the user (storing the text config somewhere and pasting it back later). Is there some other option to do this without adding db? (E.g. I thought about saving the text config (which has no confidential info) to some public paste site, though I don't know if there is one with a js api which supports anonymous uploads).

Are there other options?

Tom
  • 7,515
  • 7
  • 38
  • 54
  • That is why `Databases` exist.. – Rayon Jul 01 '16 at 17:44
  • Why not just add a db? – Pytth Jul 01 '16 at 17:45
  • You can't expect real "portability" if you limit your choice of techniques to just a client-side app. – CBroe Jul 01 '16 at 17:45
  • localStorage would be the same problem as cookies, wouldn't transfer browser to browser. – dckuehn Jul 01 '16 at 17:45
  • Localstorage is no good, because it's not portable between machines. Database is an option, but my question is about if there are simpler client-side only options available. – Tom Jul 01 '16 at 17:45
  • URLs can store ~80KB in a GET url... – dandavis Jul 01 '16 at 17:47
  • 1
    @Tom Everything available client-side will be limited to a single machine (the current client). You'll need a centralized machine, a server, to distribute information. – Jonathan Lonowski Jul 01 '16 at 17:47
  • @Jonathan Lonowski I'm looking for simple client side options without me implementing a db, like accessing some public db from the client side from a js api – Tom Jul 01 '16 at 17:49
  • Use the URL bar to store all state flags. – Malk Jul 01 '16 at 17:49
  • @Tom There are no options that are both distributed and client-side-only. – Jonathan Lonowski Jul 01 '16 at 17:49
  • @dandavis I thought URLs can store much less if we want it to be portable between browsers, but I'll check the spec – Tom Jul 01 '16 at 17:49
  • @Tom: officially, yes, in reality, URLs allow quite a bit. if you want older IE, limit it to 20KB, and if you need to support HTTP1.0 proxies, 4KB. you can use deflate() to squeeze. – dandavis Jul 01 '16 at 17:50
  • You could generate a text file for the user to download and then load the file in another computer – juvian Jul 01 '16 at 17:51
  • @Jonathan Lonowski actually, I just discovered that pastebin has some kind of api, so it's client side and distributed. Only it needs a js client api. I'll check it out. – Tom Jul 01 '16 at 17:51
  • @ juvian yes, that's one of the solution I described in my question, it's a bit cumbersome for the user – Tom Jul 01 '16 at 17:51
  • @Tom Okay. So, to clarify, your goal is to not have to write *your own* server? Pastebin and similar services are available, though you're just using *someone else's* servers instead. – Jonathan Lonowski Jul 01 '16 at 17:52
  • @Jonathan Lonowski yes, that's the point of the question. Seeking for simple client side solutions. I don't mind if the server belongs to someone else if I can use it anonymously – Tom Jul 01 '16 at 17:52
  • 1
    You could look into something like firebaseio. – Malk Jul 01 '16 at 17:54
  • @ Jonathan Lonowski thanks, I'll check it out. BTW, I used many databases in my career, so I know it's not complicated to add one to the site, but that is the boring solution that's why I asked if it can be solved client side only, I was curious about other technical options. – Tom Jul 01 '16 at 18:02
  • @Tom Is requirement to save data as plain text or `JSON` file at user filesystem? – guest271314 Jul 01 '16 at 18:08
  • 1
    You could also look at Myjson: http://myjson.com/api – juvian Jul 01 '16 at 18:10
  • @guest271314 any text is good, but local save is not, because then the state cannot be used on an other computer – Tom Jul 01 '16 at 18:10
  • @juvian thanks! I'll take a look – Tom Jul 01 '16 at 18:11
  • _"because then the state cannot be used on an other computer"_ Why cannot saved text be used at another computer? – guest271314 Jul 01 '16 at 18:11
  • @guest271314 because then the user has to transfer it to the other location which is cumbersome, inconvenient. I also mentioned this solution in my question. – Tom Jul 01 '16 at 18:12
  • @Tom Then _"without database?"_ portion of Question is not applicable? An external storage approach would be a requirement, yes? Has been some time since used, though [`Dropbox`](https://www.dropbox.com/) achieves something similar? – guest271314 Jul 01 '16 at 18:14
  • @guest271314 you are right, I'll fix it to clarify it means without implementing my own database – Tom Jul 01 '16 at 18:18
  • @Tom If am frequent user of a site, saving own data file locally would be an option that would not be too inconvenient or cumbersome; at least here. Same file could be updated, overwritten locally as wel, see http://stackoverflow.com/questions/30563157/edit-save-self-modifying-html-document-format-generated-html-javascriptl. If no sensitive data is included in file could even use private [gist](https://gist.github.com/) or [plnkr](http://plnkr.co) to save data externally. – guest271314 Jul 01 '16 at 18:22

2 Answers2

1

Based on your comments, I think Firebase might be an option for you. It is a database, but not hosted locally. You can have your client-side javascript access it directly, without cluttering your own back-end.

dckuehn
  • 2,427
  • 3
  • 27
  • 37
  • It has JS and the free plan seems more than enough for me (mine is not a commercial app, so I don't want to pay extra for this.) Looks like this is the answer for my question, but I'm not marking it solved just yet, in case somebody posts some other solution. – Tom Jul 01 '16 at 17:58
0

You could look into localStorage and use JSON.parse() and JSON.stringify() to read and write to it, respectively.

Edit: I'm sorry, just noticed you said you want it to be portable. Without a back end, that makes it very difficult unless the user is keeping his settings with him and uploading them every time he hits up the site.

Lifz
  • 690
  • 6
  • 10
  • Yes, but localstorage is not portable between computers, so it has the same problem as cookies. – Tom Jul 01 '16 at 17:47