Enable Dark Mode!
how-to-use-local-storage-and-session-storage-for-offline-functionalities-in-odoo-19.jpg
By: Ismail CA

How to use Local Storage and Session Storage for Offline Functionalities in Odoo 19

Technical Odoo 19 Odoo Enterprises Odoo Community

In web development, localStorage and sessionStorage are two important browser storage mechanisms used to store data on the client side (the user’s system). These storage options help improve performance, reduce unnecessary server requests, and enable offline functionality.

Local Storage

Local storage helps store data permanently in the browser. The stored data remains available even after:

  • Page refresh
  • Browser close
  • System restart

Because of this, localStorage is commonly used to store:

  • User preferences (e.g., Dark Mode)
  • Offline form data
  • Cached records

Eg:

If a user selects Dark Mode in Odoo and it is saved in localStorage, the UI will remain in Dark Mode even the next day after reopening the browser.

Session Storage

Session storage stores data only for the current browser tab session. Once the tab is closed, the data is automatically deleted. It is mainly used for:

  • Multi-step forms
  • Temporary workflow data
  • Page navigation states

Why Local Storage & Session Storage Are Important

These storage mechanisms are important because they help to:

  • Save records when the internet is slow or disconnected
  • Prevent data loss
  • Make screens load faster
  • Store temporary UI-related data

Working with Local Storage

1. Store data in local storage

To store data locally, we use a function called setItem('key', 'value'). It has two parameters: the left is the key, and the right is the value. We use a key to access a value.

Eg:

localStorage.setItem("theme_mode", "dark");

2. Get Data from Local Storage

To get data from local storage, we can use - getItem(‘key’) - it has one {key} parameter.

Eg:

const mode = localStorage.getItem("theme_mode");

3. Remove Data

To remove data from local storage, we have a function call - removeItem("key") -it has one {key} parameter.

Eg:

localStorage.removeItem("theme_mode");

4. Clear All Data

We also have a function to clear local storage - clear() - it has no parameter.

Eg:

localStorage.clear();

Working With Session Storage

1. Save Data

To save data in a session, we have a function call - setItem("key", "value") -  It has two parameters: the left is the key, and the right is the value. We use a key to access a value.

Eg:

sessionStorage.setItem("current_step", "step_2");

2. Get Data

To get data from session, we can use - getItem(‘key’) - it has one {key} parameter.

Eg:

const step = sessionStorage.getItem("current_step");

3. Remove Data

To remove data from a session, we have a function call - removeItem("key") -it has one {key} parameter.

Eg:

sessionStorage.removeItem("current_step");

4. Clear Session Storage

We also have a function to clear the session - clear() - it has no parameter.

Eg:

sessionStorage.clear();
I am giving a small example below of how we use it.
if (!navigator.onLine) {
    console.log("Internet is disconnected");
const formData = {
    name: "Test Customer",
    mobile: "9876543210"
};
localStorage.setItem("offline_partner_data", JSON.stringify(formData));

}
First, we are storing a small amount of data when there is no internet connection.
 window.addEventListener("online", () => {
         const data =         localStorage.getItem("offline_partner_data");
    
if (data) {
        const record = JSON.parse(data);
        console.log("Internet is back ");
        console.log("Offline data found:", record);
        // Optional: remove after logging
        localStorage.removeItem("offline_partner_data");
    } else {
        console.log("No offline data found to sync.");
    }
});

Then we are returning local storage data when the internet comes back.

Output screenshots:

1) No Internet connection

How to use Local Storage and Session Storage for Offline Functionalities in Odoo 19-cybrosys

2) Internet Connection Restored

How to use Local Storage and Session Storage for Offline Functionalities in Odoo 19-cybrosys

By using both browser storage and network status detection together, Odoo 19 applications can continue working even when the internet connection is unstable. This method helps avoid data loss, minimizes unnecessary server requests, and improves the overall user experience. It is especially useful for mobile users, POS systems, and field-based operations where internet connectivity is not always reliable. With proper implementation, browser storage makes Odoo faster, more stable, and more practical for real-time business usage.

To read more about How to Use Local Storage & Session Storage for Offline Functionality, refer to our blog How to Use Local Storage & Session Storage for Offline Functionality.


Frequently Asked Questions

What is the difference between Local Storage and Session Storage?

Local Storage and Session Storage are used to store data in the user’s browser. The key difference is how long the data remains available. Local Storage keeps data even after the browser is closed and only removes it when the user clears it manually. Session Storage stores data temporarily and automatically deletes it when the browser tab or window is closed.

When should Local Storage be used in Odoo applications?

Local Storage should be used in Odoo applications when data needs to persist even after the browser is closed. It is commonly used to store user preferences, cache frequently accessed data, and temporarily save information during offline or unstable internet conditions. This helps improve performance and ensures a smoother experience, especially for mobile users or field staff who may face connectivity issues.

Is it safe to store business data in Local Storage?

Local storage is not recommended for sensitive or confidential information because the data is stored directly in the browser and can be accessed through developer tools. Sensitive data such as authentication tokens, passwords, or private customer information should always be handled securely through server-side logic or protected APIs.

How much data can Local Storage store?

Most modern browsers allow around 5MB to 10MB of storage per domain for localStorage. While this is enough for small datasets, it should not be used as a replacement for a database. Large datasets should still be handled through server-side storage.

Can Local Storage improve Odoo performance?

Yes. By caching frequently used data locally, applications can reduce repeated server requests. This can improve page loading speed and provide a smoother user experience, especially in environments with slow or unstable internet connections.

Do Local Storage and Session Storage work on all browsers?

Yes, both are supported by all modern browsers, including Chrome, Firefox, Edge, and Safari. However, storage limits and behavior may vary slightly depending on the browser and device.

If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, KINFRA Techno Park
Kakkanchery, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message