Reputation: 5472
So I have a chrome extension that I'm implementing with IndexedDB. The extension uses a content script which stores a record to the database every time the user casts a vote on a comment. I'm wondering how frequently I should open and close the connection.
Upvotes: 3
Views: 1774
Reputation: 1113
I was closing my database connection whenever I don't need it anymore, but it caused too many bugs because there is no way to know if a database is opened or not.
So I'm doing the same, never closing. All connections will be closed when the browser tab is closed.
Upvotes: 0
Reputation: 13131
I never close the connection and never see problem.
Just make sure, you listen to onversionchange of idb (not idb open request) to close the connection. It is the only time to close the connection. Otherwise browser will close for you.
Upvotes: 1