JavaScript connection module with online/offline events