- All
- HTML
Powered by AI and the LinkedIn community
1
What is local storage?
2
What are cookies?
Be the first to add your personal experience
3
Advantages and disadvantages of local storage
4
Advantages and disadvantages of cookies
Be the first to add your personal experience
5
How to implement fallback solutions
Local storage and cookies are two ways to store data on the client side in HTML. They can be useful for saving user preferences, authentication tokens, or other information that does not need to be sent to the server every time. However, they also have some drawbacks and limitations that you should be aware of. In this article, we will compare the advantages and disadvantages of local storage and cookies, and show you how to implement fallback solutions for older or unsupported browsers.
Top experts in this article
Selected by the community from 3 contributions. Learn more
Earn a Community Top Voice badge
Add to collaborative articles to get recognized for your expertise on your profile. Learn more
- Marco Montalto Monella Software Engineer | SRE at Microsoft Azure Cosmos DB | ex-Meta | Public Speaker | Automating databases
4
- Mohamed Iyad Chafroud Senior Full stack Developer at CXG | React.js, Node.js, Typescript
1
- Sean Bailey Software leader who hangs off of bridges sometimes
1
1 What is local storage?
Local storage is a feature of the HTML5 specification that allows you to store key-value pairs of data in the browser. Unlike cookies, local storage data is not sent to the server with every request, which can improve performance and reduce bandwidth usage. Local storage data can also persist across sessions, meaning that it does not expire or get deleted unless the user clears it manually. Local storage can store up to 5 MB of data per domain, which is much more than cookies.
Help others by sharing more (125 characters min.)
- Mohamed Iyad Chafroud Senior Full stack Developer at CXG | React.js, Node.js, Typescript
- Report contribution
Thanks for letting us know! You'll no longer see this contribution
Utilisation de techniques de stockage alternatif : Vous pouvez recourir à d'autres méthodes de stockage côté client comme les variables de session, les données cachées dans la page ou l'utilisation de technologies telles que userData pour Internet Explorer.
Translated
LikeLike
Celebrate
Support
Love
Insightful
Funny
1
2 What are cookies?
Cookies are small pieces of data that are sent from the server to the browser and stored in a text file. Cookies can be used to store session information, user preferences, or other data that needs to be accessed by the server. Cookies have a limited size of 4 KB per domain, and can expire or be deleted by the user or the browser. Cookies can also be blocked or restricted by the user's privacy settings or browser extensions.
Help others by sharing more (125 characters min.)
3 Advantages and disadvantages of local storage
Local storage has some advantages over cookies, such as the ability to store more data per domain (5 MB vs 4 KB), not affecting network performance or bandwidth usage, persisting across sessions and browser tabs, and storing complex data types, such as objects or arrays. However, local storage also has some disadvantages, such as not being supported by older browsers, not being accessible by the server, being vulnerable to cross-site scripting (XSS) attacks, and being cleared by the user or the browser, which can cause data loss or inconsistency.
Help others by sharing more (125 characters min.)
4 Advantages and disadvantages of cookies
Cookies have some advantages over local storage, such as being supported by almost all browsers, even older ones, and allowing the server to access them, which can enable authentication or personalization. Additionally, they can be set to expire or be deleted automatically, which can prevent data accumulation or privacy issues. However, cookies also have some disadvantages, such as being able to store only a small amount of data per domain, affecting the network performance or bandwidth usage, being blocked or restricted by the user's privacy settings or browser extensions, and being vulnerable to cross-site request forgery (CSRF) attacks.
Help others by sharing more (125 characters min.)
5 How to implement fallback solutions
If you want to use local storage or cookies in your HTML application, you should always check for their availability and compatibility before using them. You can use code snippets to detect if the browser supports local storage or cookies. If not, you can use fallback solutions such as a polyfill library, server-side storage, URL parameter, or a hidden form field. However, these solutions may have limitations or drawbacks, such as requiring additional libraries, depending on the availability of the server, exposing data, or not persisting across sessions. Therefore, you should consider the pros and cons of each solution and choose the one that best suits your needs and requirements.
Help others by sharing more (125 characters min.)
- Marco Montalto Monella Software Engineer | SRE at Microsoft Azure Cosmos DB | ex-Meta | Public Speaker | Automating databases
- Report contribution
Thanks for letting us know! You'll no longer see this contribution
Snippet to check local storage support:```if (typeof(Storage) !== "undefined") { console.log("Local storage is supported"); } else { console.warn("Local storage is not supported");}```Snippet to check if cookies are enabled:```if (navigator.cookieEnabled) { console.log("Cookies are enabled");} else { console.warn("Cookies are disabled");}```
LikeLike
Celebrate
Support
Love
Insightful
Funny
4
- Sean Bailey Software leader who hangs off of bridges sometimes
- Report contribution
Thanks for letting us know! You'll no longer see this contribution
The Local Storage and cookies browser APIs are incredibly well-supported. According to Caniuse.com, 96.5% of all browser traffic worldwide supports Local Storage, including modern versions of all major browsers. If you're using bleeding-edge web technologies, it's always a good idea to polyfill, but unless you're building for a very specific and antiquated use case, I would not worry about using a polyfill or stopgap solution for Local Storage or cookies.
LikeLike
Celebrate
Support
Love
Insightful
Funny
1
HTML
HTML
+ Follow
Rate this article
We created this article with the help of AI. What do you think of it?
It’s great It’s not so great
Thanks for your feedback
Your feedback is private. Like or react to bring the conversation to your network.
Tell us more
Tell us why you didn’t like this article.
If you think something in this article goes against our Professional Community Policies, please let us know.
We appreciate you letting us know. Though we’re unable to respond directly, your feedback helps us improve this experience for everyone.
If you think this goes against our Professional Community Policies, please let us know.
More articles on HTML
No more previous content
- How do you make your HTML code semantic? 75 contributions
- How can you manage HTML projects within scope, budget, and timeline? 52 contributions
- How do you link to external stylesheets and scripts? 64 contributions
- How do you add CSS and JavaScript to HTML challenges? 50 contributions
- How do you manage your styles with CSS variables? 39 contributions
- How can you create web-based reports with HTML? 76 contributions
- How do you create reusable and maintainable CSS style rules? 53 contributions
- How do you test HTML portfolio accessibility and usability? 38 contributions
- How do you define the main sections of a web page using HTML? 73 contributions
- How do you apply CSS styles to different devices? 34 contributions
- How can HTML comments and meta tags improve your portfolio? 67 contributions
- How can you quickly learn or update your HTML knowledge? 88 contributions
- What are the hottest HTML roles and skills for you to learn? 46 contributions
- How can you master advanced HTML features and topics? 11 contributions
- How can you scale fonts on your website? 9 contributions
No more next content
More relevant reading
- HTML5 How can you use HTML5 local storage instead of cookies?
- Computer Literacy How do you troubleshoot web browsing errors?
- IT Operations What are the most effective web browser troubleshooting techniques?
- OAuth What are the trade-offs between implicit grant flow and authorization code flow?