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";

@no_one 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)

No, it’s not socketio, i made it with js

My dear @no_one, that is NOT a static website. That is a dynamic page, it uses Node.js.

I asked you and now you’re asking me. How wonderful.

Are you sure you made it?

1 Like

yes, i made it, but most of the code is just the default glitch express dream list thingy.

It is not. It is using an SQLite database. And it’s clearly written in the README.

2 Likes

listen, i just added css and a button. k?
It is just a remix of the default glitch dream list project

That’s the ~hello-sqlite project.

I’ll make it more clear for you.

It uses SQLite which is a database system to store all the stuff.

1 Like

apparently i get the same dream list with express.

Express is a routing framework. Not a database.

1 Like

But i get the same thing, try it!

Which project? ~hello-express?

yee

In hello-express,

  • the project is not a static site
  • the data stored is temporary, it’ll be cleared when the container restarts or goes to sleep. Basically after 5 mins of inactivity.
2 Likes

oh, ok. I’ll find other methods

1 Like

You could try the hello-commento starter that I made.

It’s a simple comment system.

3 Likes

Thanks for the suggestion!
Oh, i need to pay… no thanks!

No you don’t need to.

2 Likes

Huh? What?
Oh…

It’s open source…

3 Likes

why does it say “30-day trial”?

https://docs.commento.io/installation/self-hosting/on-your-server

1 Like

i cannot really pay for a domain, i need to embed it.

Uhm, you can just use the .glitch.me domain. I did that for a few days until Glitch activated my custom domain (comments.aboutdavid.me)

1 Like

lemme try

Uhm, in the comments it says that i’ve got an incorrect password/email, but when i log in to the dashboard it logs me in succesfully, you should fix that!

I didn’t make commento, I just make the Glitch starter kit.

hmm, wierd.

Your best bet is just to learn sql:

3 Likes

well you’re going to need some way to get those arrrays from one computer to another. they don’t just appear on every computer like a scratch global variable

you can save them into cookies with JSON.stringify but a user would only be able to see their own comments.

1 Like

That’s cool, i could make a notes page where you save your notes

You would only have 4kb of storage for that

2 Likes

IndexedDB to the rescue!

1 Like

@khalby786 does indexed databases clear along with cookies?

It’s also worth noting if some one where to clear their browsing history that the cookies will be deleted. It’s like fresh cookies being thrown out the window. But it’s a lot worse.

smart humans can uncheck the clear cookies and browsing data when clearing their history lol.

Let me test that indexeddb thing

So, I just checked in the “clear cookies” button and the indexedDB example i was looking at was cleared. So I guess it does…

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.