‘HTML5 localstorage’ címkét tartalmazó cikkek
In this Article I am endeavor to do a demonstration in HTML5 to be introduced data storage modul (Web Storage) of a client side. Naturally it will not change the World as it seems – since the “cloud” we know that it will -, but nevertheless it assures a great option which we could solve only with different tricks so far (e.g.: Cookie). But the Cookie had many disadvantage (limited size 4KB, traffic through the forwarding per request etc.). Well on the other hands the HTML5 Web Storage by the current definition can store 5MB data per source. Plenty of data can be stored here. It is important aswell that no unnecessary traffic will spring up because it is not sending data only if we ask. (by the way it is not done to make 5MB storages)
The Web Storage itself stores the data in a key/value pair form and we can search back with this in a later time when we need it. The type of the key is text while the type of the value can be anything. Let’s see the types of the storage:
1. Session Storage
The data will be stored here until the end of the browsing Session. After that they will be deleted (this can redeem the cookies). As long as the data will not be important to us in a later time, or for users, it is worthwhile to use this solution due to saving of the resources.
2. Local Storage
It is a different case like the previous. The data will be stored here and remains until we will not delete the key/value pairs or the user will not do this with his/her browser. Now You could ask why is this so good? Because e.g.: if a user opens a new window he/she can get the data or if he/she quits from his/her browser and re-enter, the data will be available. Tovább olvasom »
A HTML5-ben bevezetésre kerülő kliens oldali adattároló modul (Web Storage) bemutatására törekszek ebben a cikkben. Természetesen nem fogja megváltani a világot – hisz a “felhő” óta tudjuk, hogy az fogja -, de ettől függetlenül egy nagyszerű lehetőséget biztosít, amit eddig csak különböző trükkökkel tudtunk megoldani (Pl. Cookie (süti)). De a süti számos hátránnyal járt (korlátos méret 4KB, +adatforgalom a kérésenkénti küldés miatt, stb.). Nos, ezzel szemben a HTML5 web storage a jelenlegi definíció szerint 5MB adatot tud tárolni és ráadásul forrásonként. Ide azért már pakolhatunk adatot bőven. Az is fontos, hogy itt már nem keletkezik plusz felesleges adatforgalom, hiszen nem küldözgeti az adatokat, csak ha kérjük. (azért nem illik 5Mb-os storage-eket készíteni)
Maga a Web Storage az adatokat kulcs – érték páros formájában tárolja el és ennek segítségével tudjuk azokat visszakeresni. A kulcs típusa szöveges, míg az érték típusa bármi lehet. Nézzük, milyen “fajtái” vannak:
1. Session Storage
Az ide kerülő adatokat a böngészési Session végéig tárolja, utána törlésre kerülnek (ez hivatott kiváltani a Cookie -kat). Amennyiben az adatok később nem lesznek fontosak számunkra, vagy a felhasználó számára, érdemes ezt a megoldást választani az erőforrások megtakarítása végett.
2. Local Storage
Az ide kerülő adatokkal már más a helyzet, ezeket egészen addig megmaradnak, amíg nem töröljük a kulcs-érték párokat, vagy a felhasználó nem törli azokat a böngészőjével. Hogy miért is jó ez? Nos, pl. ha a felhasználó egy új ablakot nyit, akkor is eléri az itt tárolt adatokat, vagy ha kilép a böngészőből és újra belép, akkor is elérhetőek maradnak. Tovább olvasom »