Cookies Practice

General question here; I’m working on a side project where I will be tracking student performance as it is related to a few different variables (e.g. instructor, time of day, time of week, subject, etc.). Before the question comes up, there are no names of students or any identifiable information being used here and it is, at the moment, just a side project for my benefit and curiosity. Ultimately, I want to see where and when the good and bad behaviours are occurring.

To make the data entry bearable, I have two years of observed behaviours to comb through, I need a variable that’ll permanently store the information for me so that I can access and add to it at a later date. If that information is stored only on one machine that that’s okay.

**Being a novice here, I have two questions: **

1. Is a cookie a viable option for this?
2. If so, have you kind and beautiful folks got any suggested sites where I can practice using them? Something like codecademy would be cool where I can hold a friendly hand for a few steps before running alone.



A bit more information would be helpful. What technology are you using to create this application? Is it a purely front-end application? In general, the way that a cookie works is that the cookie is sent to the client from the server and it is stored in the browser. You can create a cookie using document.cookie = someJavaScriptObject. If you set the expires property of this object to a date far in the future, the cookie should stick around in the browser until that date, unless the cache is cleared. This wouldn’t be a recommended method for persistence however since you are storing the information on the client machine and then have to ask the server to decipher it anyway. A better method would be to link the server to a database, or write the object out in a *.csv or *.json file.

More information on cookies can be found here. I hope this helps!

1 Like

I only have a very loose sense of what you’re aiming for, but if you want to comb through lots of data and pull out the bits that meet specific conditions, you want a database for this.

This requires a bit of backend knowledge that you can pick up working through the backend curriculum and projects here.

FCC focuses on Node and MongoDB, which is pretty straightforward once you get over the initial hump.

Sidenote: I’m a high school teacher and I’m always tinkering with making apps like these - if you wanna bounce ideas off me, I’m happy to be a sounding board, so feel free to PM me anytime :slight_smile:

1 Like

Thanks you two. To answer your questions, i am trying to write this using only front-end tech, due to my own ignorances at the moment.

Ultimately, I want to export the data (e.g . On this date, in this class, with this teacher, student A performed well) to a site I’m building populating a bar chart.

So, I want a large data set that will be used to make a group of bar charts; all in an effort to visualize the stimuli and situations that have an effect on learning.

IMO, cookies are probably not the way to go here. Aside from the complexity and computational cost of trying to correlate a large data-set from cookies, there is also the storage aspect, most browsers only support up to 4KB of cookies from a single domain. This could cause problems because of how persistent cookies are deleted, if the cookie grows too large, it cannot be deleted.

I probably would focus on working a persistence tier into the project. NodeJs and MongoDB are probably the easiest example of this to learn (and as @JacksonBates mentioned, there are projects here to help you learn them). PHP is also a fairly easy server-side technology to pick up, if you felt inclined.

Hope the project goes well for you!

1 Like


Hi Doug, Cookies, sessions and tokens are used in systems with authentication, which is a process to identify that users are who they say they are. That’s related to authorization which enables users to access data depending on who they are (once authenticated). Understanding those definitions was a huge a-ha moment for me! There’s a lot to this subject, but here’s some basic info.

Cookies, tokens, sessions are handy because a typical server request a stateless protocol which means that it treats each request as an independent one, with no knowledge of any previous request. When you have a cookie stored in the user’s browser, that cookie gets sent along with the request. You can define the cookie you send to the user to contain basic information so the server can recognize who the request came from. Ever notice how when you clear your cookies, you get logged out of your favorite sites? Cookies are also typically encrypted with hashing so that if the data is intercepted or the computer is lost, the data in the string can’t be understood. You should carefully consider what information you send in the cookie (AKA no passwords or personal information) since it’s possible to decode them. As JavaTheNutt pointed out, there are also size restrictions for cookies so they are generally not used as data storage for information otherwise hosted on a server.

So cookies are used to create a persistent state so users can access their data when they return to a website or navigate from one page to another. Otherwise the server would need to receive login credentials each time! The decision to use cookies (or sessions or tokens) depends on whether your student tracking app will have user registration and login and needs to control how users will access data from their browser.

As far as presenting the student data, I see a couple of routes you could take. If you can grab the information from the file system, you can load the data into local memory, manipulate it inside of a script, and then output it in a format and structure. This is handy if you’re looking to transform the data into a static form that can be used for a specific purpose, like say building a d3.js graph that shows how student performance relates to your variables.

The second option would be to transfer the data into database which becomes a permanent repository for the data. Then you can write queries to parse the data yourself and/or expose that database to users by building an API, which let’s users query the database through an interface that you build, like a web application.

This is all very general but hopefully this gives you a bit more insight into cookies and different options available. All of these methods are accessible through Node.js, which is a good one to learn especially if you’re already familiar with javascript.

1 Like

Hello, I moved this to the right category as it is not a wiki.

Yeah, I still have a little bit to go with the front-end stuff here so, the back-end is a mystery. Hence my thought process being narrowed to a front-end only solution. Thanks, I’m putting the project on the back-burner for a while.


Very informative for me, still a newb. I’m couching the project till I get an feel for the back-end. Thanks though.

If security really isn’t an issue (I.e student data is anonymised and it genuinely wouldn’t matter if the data was leaked) you could try something like I believe this let’s you have a very simple, Excel style, storage system.

I haven’t used it, but they’ve mentioned it a couple of times on the Shop Talk Show podcast as a decent alternative to backend data storage if you are more comfortable as a front-ender.

But the security issue is key!


See also:

Don’t use it if you can’t suitably mask the API key or if the data is in any way sensitive.