htmldomcustom-data-attributesession-storagesessionstorage

When to use session storage vs html data attributes to save DOM state


I would like to know if there are some clear situations where one should use html data attributes to store DOM state instead of using session storage.
By DOM state I mean if a component is open/closed, visible/invisible,...
I'm using both but I have no idea what's the best approach (performance related).


Solution

  • Typically, working with the DOM is slower than just about any other API. Working with sessionStorage may turn out to be faster since it is a WebAPI and can be processed asynchronously from other JS code. It is also much simpler to work with.