Where is the better place to keep the chat records of web chat?

made a websocket chat room.

encountered a problem. Where is a better place to keep chat records?

clipboard.png

Friends list requests the server"s chat history interface (that is, to switch chat objects) when clicking Friends , but it doesn"t feel right to ask for it every time you click.

so I want to save the record.

Local Storage , Session Storage , IndexedDb ,.

I don"t know which way is better

Please state the advantages, disadvantages and implementation ideas of the ways you think are better (not limited to the above three, as long as you feel good)


closures should be appropriate. Data can be temporarily stored in memory without being released and accessed quickly.

(function(){
    var obj = {};
    function saveDate(id, data){
        //
        obj[id] = data;    
    }
    function getData(id){
        let data = obj[id] ? obj[id] : '';
        return data;
    }
    function clearData(){
        obj = null;
    }
    return {
        setData : setData,
        getData : getData,
        clearData: clearData
    }
})()
Menu