niedziela, 14 sierpnia 2016

HTML 5 Local Storage vs Cookies

While I was solving Weekly Javascript Chalange Task 3 I ask my self a quite interesting question. What is a difference between Local Storage and Cookies?
Somebody already asked that question on SO:  http://stackoverflow.com/questions/3220660/local-storage-vs-cookies ,and there is a very good answer:

Cookies and local storage serve different purposes. Cookies are primarily for reading server-side, local storage can only be read client-side. So the question is, in your app, who needs this data — the client or the server?
If it's your client (your JavaScript), then by all means switch. You're wasting bandwidth by sending all the data in each HTTP header.
If it's your server, local storage isn't so useful because you'd have to forward the data along somehow (with Ajax or hidden form fields or something). This might be okay if the server only needs a small subset of the total data for each request.
You'll want to leave your session cookie as a cookie either way though.
As per the technical difference, and also my understanding:
  1. Apart from being an old way of saving data, Cookies give you a limit of 4096 bytes (4095, actually) - its per cookie. Local Storage is as big as 5MB per domain - SO Question also mentions it
  2. localStorage is an implementation of the Storage Interface. It stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser Cache / Locally Stored Data - unlike cookie expiry.

 Why I mention about it? For two reasons:
a) I use this blog as my notepad, that I sometimes visit
b) this question have a great "interview question" potential



sobota, 13 sierpnia 2016

Weekly JavaScript Challenge

This note is to promote some great event that I have found in internet.

Michał Miszczyszyn is one of polish javascript community leader and he starts new weekly javascript chalange. It works, that Michał ones a week create new javascript task, and any competitor can join and try to solve that task. After that time (about one week) Michał takes responses and makes code review.
When he finish code reviews he put task review on his blog.

What a great oportunity for learning new language with code review. Seems great. What you think about it?

I think, that I try to solve some challenges in my free time, but not guarantee that they where will appear regular.

Links:
Michał blog: https://typeofweb.com
Michał blog posts about chalange: https://typeofweb.com/tag/weekly-javascript-challenge/
facebook group where we can find news about new challenge: https://www.facebook.com/groups/1131907053499522/
First task event: https://www.facebook.com/events/997187053723327/
My solutions on github: https://github.com/zchpit/WeeklyJavaScriptChallenge
My solution for task 1 in jsFindle: https://jsfiddle.net/vknqwnb8/15/