Save arrays with js

So in my website, i have made a js array for comments: https://freezing-honeysuckle-quill.glitch.me/
But the problem is, after i leave a comment, reload the page, they’re gone!

How can i program a script to save the comments? Can i do that with cookies?

It is advisable to use a persistent database, especially for something like a comment system.

Cookies and localStorage store data that is only visible to a particular browser, and they’re not visible to other users, which is is not something you would want for a comment system. Because in a comment system, you should be able to see comments by everyone and not just yourself (unless you want some self-motivation :wink:). Also, cookies and localStorage can get cleared when you clear your browser cache. Therefore I conclude, cookies and localStorage are not suitable places to store data.

2 Likes

If you are looking for a good database, I would have to recommend MySQL. Its easy to learn.

1 Like

Of course, that is debatable. So I’m not going to say which is better than which but rather, I’m gonna say which all are good databases.

  • MySQL
  • MongoDB
  • SQLite (works best for Glitch)
  • Redis
  • Postgres

If it’s your first time using databases, you can use adapters like https://endb.js.org or https://quickdb.js.org.

There are usernames and passwords involved for most of these databases, so it’s essential that you have a backend/server. Recommended: Node.js.

I’m not saying PHP is bad for databases, but Node.js has more support for databases these days and more secure. Again, it’s your choice.

1 Like

PHP

PHP is the most popular backend on the internet (>75% of sites use it). You can find a package for almost any database.

Read the spoiler text, please. :wink:

1 Like

Read the spoiler text, please. :wink:

1 Like

Ok, let’s not turn this into a battle between who’s better: Node.js vs PHP.

Your choice. Use the one you feel comfortable with.

1 Like

I agree with @khalby786

1 Like

Let’s not use this format it’s annoying

Anyways, can i do that on STATIC websites?

there’s no way you will be able to view user submitted content, unless you send the data to somewhere everyone can access. If you want to keep your site static just rely on a external service or create a comment box that stores in somewhere decenteralized like ipfs

Uhm, can i do that with cookies?

document.cookie = "Comment1=Nice Website!; expires=Thu, 18 Dec 9999 12:00:00 UTC";
document.cookie = "Comment2=Woooow!; expires=Thu, 18 Dec 9999 12:00:00 UTC";
document.cookie = "Comment3=How did you do that?!?!; expires=Thu, 18 Dec 9999 12:00:00 UTC";

@LankyBox01 you can use third-party comment services on your static site with a minimum of fuss.

<div class="commentbox"></div>
<script src="https://unpkg.com/commentbox.io/dist/commentBox.min.js"></script>
<script>
   commentBox('my-project-id')
</script>

Before you begin, please create a project in the CommentBox.io Dashboard. Click here to learn more about the dashboard and how to use it.

1 Like

I just feel like it’s wrong, and that still doesn’t answer my original question.
I wanna make it with javascript arrays!

Well, there are limitations with what you can make with only JS arrays.

1 Like

example?

1 Like

A comment system.

4 Likes

Good point, but i actually wanna make a system of commenting, not a comment system.

What’s the difference?

you tell me.

Listen, how does this work: https://heymessage.glitch.me/
I wanna know so badly
(even tough i made it)