Save Game Data in Html5 and Javascript

Asked

Viewed 498 times

1

I would like to know how I can make a "cache" of a project of mine, because the game works normally, but when updates the page, all progress is lost, I would like to know how I can make this "cache" so that the progress is saved in the user’s browser.

Obs:

  • for example the game Cookie Clicker, that saved browser progress.
  • I developed the game in Javascript and HTML
  • The progress of the Game is placed on tag <Label> and I would like that to be saved.

Thank you very much in advance!

  • 2

    You need to save the information to a cookie. https://mariovalney.com/como-usar-cookies-com-javascript/

  • If you are using pure JS follow @Mauroalexandre’s suggestion, otherwise tell us which framework you are using.

  • 1

    You can also use LocalStorage, it holds more data than cookies(http://www.w3schools.com/html/html5_webstorage.asp), but there is the possibility that older versions of browsers do not support the LocalStorage(http://caniuse.com/#feat=namevalue-Storage).

1 answer

1


One of the possible solutions would be to use the localStorage

The library persist-js may also be a good alternative; it automatically uses the localStorage if the browser supports, or cookies if the browser is older.

  • Thank you to everyone who commented, I used localStorage and it worked the way I wanted! Att André Neto

Browser other questions tagged

You are not signed in. Login or sign up in order to post.