Check if user is offline

It's pretty easy to check if a user is offline with javascript.

window.addEventListener('offline', () => console.log('is offline'))

This can be useful to display a warning if your application auto-saves at a regular interval.

If the user is offline, the auto-save may fail so a warning message would be a good bit of UX here.

That's me!

I’m Ajay Karwal. I write about my experiences as a front-end developer. If you enjoy my content, please consider supporting what I do.

Become a PatronBuy me a coffee