Understanding local storage, session storage, and cookies
Posted: January 24, 2024
Client-side cookie consent local storage mechanisms are technologies within a browser that enable websites to store information locally on user devices.
These technologies are like mini-storage capabilities attached to a browser that improve the user experience and enhance website functionality.
The three main client-side storage mechanisms are:
- Local storage
- Session storage
- Cookies
Cookies and privacy go hand-in-hand, because you’re capturing some level of data. Many countries now have specific cookie law implications that need to be considered to ensure you’re remaining compliant when storing and using browser cookies, however they are stored.
From remembering user preferences to enabling offline access, each of the client-side storage mechanisms serves a different purpose and has distinct privacy implications that we outline in this post.
What is Local Storage?
Local storage is a type of web storage method that allows website owners to store data on a user’s device in the form of key-value pairs. This web storage method does not expire even upon the user closing the window or tab; the data continues to exist in the browser unless the user clears the browser data cache to erase all local storage data.
Local storage has significant advantages over cookies. Unlike most cookies, which are often cleared upon closing the browser, local storage continues to exist on the user device for a lifetime unless the user deletes it manually. While cookies have limited memories (typically up to 4KB) local storage can hold several megabytes, depending on browser limitations.
Beyond basic storage, local storage unlocks immense possibilities for websites. It allows websites to access locally stored data even when offline. It enables offline browsing, which is suitable for saving drafts on online writing tools or drawing apps to prevent accidental loss.
Local storage undeniably offers benefits for websites and web apps, but data having to be manually deleted or unnoticeably persisting on user devices raises concerns about long-term data retention. It also impacts the user’s ability to make informed choices if they’re not fully aware of what data is locally stored and for what use.
Data stored locally can also be used for tracking users even when they are offline. Websites need to have clear privacy policies highlighting how local storage data is collected, used, and shared. Under CCPA, data subjects have the right to opt-out if local storage data is shared with third parties for “sale” or advertising purposes.
What is Session Storage?
Session storage is very similar to local storage. Session storage is created every time a new document is loaded in a particular tab of a browser. It is typically used for storing temporary data for the current browser session. It differs from local storage in that, while local storage doesn’t expire unless manually deleted, data in session storage is cleared upon closing the page session.
Compared to local storage, there are fewer legal implications with session storage. Temporary data holding reduces privacy concerns, and as the data automatically clears upon session closure, security risks also potentially decrease. However, privacy risks like linking with other data to identify individuals remain.
For compliance purposes, it is important to determine if session storage data can be combined with other information to potentially identify individuals.
What are the different types of cookies?
Cookies on behalf of the party by which they are stored in browser directories of users are divided into two types:
- First-party cookies
- Third-party cookies.
When a user interacts with a website, cookies can be created by either the domain being visited itself or domains other than the website. Ultimately, which domain’s server drops the cookies in the user’s browser decides the type of cookies.
Read more about zero party vs. first party vs. third party data.
First-party cookies
First-party cookies are created by the website itself, which a user interacts with. When a user interacts with a website, its server sends instructions to create a domain-specific cookie file in the user’s browser. The information stored in this cookie contains details regarding user preferences such as language and sign-in details, shopping cart contents, and analytics data.
Analytics data could be information about website usage (e.g. page views, average time spent on each page, bounce rate, user movement through the website), user interaction (buttons and links clicked, forms submitted, downloads), and user information (device type, operating system, browser, location, etc.).
First-party cookies are retrieved by the domain host upon subsequent visits by the user, allowing website hosts to gather statistical outcomes and boost the browsing experience of the user. These cookies can only track user activity on the original website where the cookies were placed, not other websites. It makes them less privacy-invasive.
Third-party cookies
Third-party cookies are created by websites other than those with which a user interacts. Often, websites have embedded scripts, like ad trackers, from social media platforms or advertising networks that set their domain-specific cookies on the user’s browser. Third-party cookies contain information about the user’s browser and device, as well as potentially some browsing history data.
Website owners mainly place these cookies on their websites to earn ad revenue. Their reliance is also driven by cost-effectiveness, so they don’t need to develop their own versions of features like social media widgets (share buttons, comment sections), live chat support (connecting users with customer service representatives), payment processing (integrating with secure payment gateways), etc.
As a user browses through the web, these cookies, wherever they’re embedded, act like beacons and allow the third party to track user activity across different websites. These cookies, thereby, help third parties build a profile of users’ interests and online behavior. This raises serious privacy concerns.
Many regulations, like GDPR and CCPA, require websites to obtain user consent for storing and tracking data through third-party cookies. Due to its privacy-invasive nature, major browsers have already started blocking it by default. Google has announced plans to phase them out by the end of 2024.
Other cookie types:
- Strictly necessary cookies are usually first-party cookies. These cookies do not require user consent. Most cookie laws, including the EU GDPR, exempt necessary cookies from collecting user consent before performing their actions.
- Performance cookies do not collect personally identifiable information (PII), but the data they gather is typically anonymous, like page views, clicks, time spent on each page, etc. Often, performance cookies are perceived as first-party cookies, but they could be third-party cookies too.
- Functional cookies are also referred to as preference cookies. These cookies can be both first-party and third-party. They do not store PII specific to users, but they may indirectly link to a user through device information or browsing behavior.
- Targeting cookies are also known as advertising cookies. Such cookies are mostly third-party cookies. These cookies collect user information about their browsing habits and interests across different websites. These generally lack transparency and collect data extensively; therefore, regulations like GDPR and CCPA require explicit user consent for these to be used.
Local Storage vs Session Storage vs Cookies: Choosing the right option for you
Choosing the appropriate storage options for a web application varies with the project’s specific requirements and constraints. Determining which storage mechanism best suits the project’s requirements involves factors like data size, data persistence, and data isolation.
- For small amounts of data storage, such as user preferences, cookies for their small storage capacity can be the best option. On the other hand, for extensive data sizes, local storage is a preferable choice. However, websites should be mindful of browser limits, as excessive data storage may lead to delayed website loading.
- Session storage does the job accurately for data that is only required for a current browsing session. For data to persist beyond the current browsing session and be stored indefinitely or until explicitly removed, local storage is a suitable option.
- For storing specific data about a particular browsing session without mixing it with other sessions, session storage is an ideal choice. For data to be shared across multiple domains or subdomains within the same origin, cookies are a viable option.
Privacy implications with local storage, session storage, and cookies
Navigating the complex landscape of data privacy regulations, especially for websites utilizing cookies, local storage, and session storage, requires careful consideration and understanding to comply with relevant laws and directives.
Storing personal data in any form, whether it’s in cookies, local storage, or session storage, requires the consent of users. Not showing local storage and session storage in your cookie declaration report or not blocking them before getting consent from users can put you on the opposite end of privacy laws, especially GDPR.
For cookies and similar technologies that entail tracking and processing personal data, GDPR mandates obtaining explicit consent from users. CCPA requires businesses to be transparent about their data collection practices and disclose the use of cookies and web storage technologies to users, informing them about what data is collected and for what purposes.
Collecting data through local storage, session storage, and cookies can be GDPR- and other privacy laws-compliant, given that website owners inform users about their personal data collection and provide them with control to opt out of unnecessary data collection, manage stored data, and request data deletion.
Additionally, websites should have a legal basis for processing data. It could be “legitimate interest” for essential functionality or “consent” for non-essential features. Websites should also have policies for the data minimization principle, which requires collecting and storing only the minimum session data necessary for intended purposes and deleting it after requirements are met.
Understanding client-side storage mechanisms plays an important role in building efficient and interactive web applications. Choosing the right option depends on the project’s specific requirements and constraints.
While client-side storage cuts reliance on constant communication with servers to improve performance and user experience, it comes with privacy implications and, therefore, requires careful compliance consideration for developing user trust and respecting their privacy rights.
By adhering to privacy best practices, offering granular consent options, and providing clear disclosures, website owners can win user trust and cultivate a privacy-respecting environment.
Download our ITP and Cookies guide
As leading browser technologies take significant strides to safeguard users’ online data privacy, the advancements have far-reaching implications for the Ad Tech industry, changing the way marketing data is collected, stored, and utilized.
Our comprehensive guide addresses key questions businesses need to ask:
- How will advancements in browser technologies impact digital marketing?
- What are the changes in browser privacy?
- What is intelligent tracking protection (ITP)?
- What is the business impact?
- How Cassie helps